muhamadhhassan / laramost

This package includes Mattermost drivers for Laravel different features like logging and notifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laramost

Laramost is a Monolog handler channel for Laravel that allows you to send log records to a mattermost channel.

Installation

$ composer require muhamadhhassan/laramost

Levels

Monolog levels are used to set the message color and icon

Level Name Level Value Color Emoji
DEBUG 100 #91C4EB ๐Ÿ”
INFO 200 #91C4EB โ„น๏ธ
NOTICE 250 #99cc33 ๐Ÿ“
WARNING 300 #ffcc00 โš ๏ธ
ERROR 400 #cc3300 ๐Ÿ›
CRITICAL 500 #cc3300 โŒ
EMERGENCY 600 #cc3300 ๐Ÿšจ

Usage

In Laravel Apps

In your config/logging.php add the mattermost channel to the channels array:

use LaraMost\Formatter\MattermostFormatter;
use LaraMost\Handler\MattermostWebhookHandler;

'channels' => [
    'mattermost' => [
        'driver'  => 'monolog',
        'handler' => MattermostWebhookHandler::class,
        'formatter' => MattermostFormatter::class,
        'with' => [
            'hook' => 'https://your-mattermost.com/hooks/xxx-generatedkey-xxx',
        ],
        'level' => 'error'
    ],
],

Then simply, using Laravel Log facade:

Log::channel('mattermost')->error('Something went wrong', ['user_id' => 5]);

In any PHP Apps

use Monolog\Logger;
use LaraMost\Formatter\MattermostFormatter;
use LaraMost\Handler\MattermostWebhookHandler;

$logger = new Logger('application');
$handler = new MattermostWebhookHandler('https://your-mattermost.com/hooks/xxx-generatedkey-xxx', Logger::ERROR);
$handler->setFormatter(new MattermostFormatter())
$logger->pushHandler($handler);

$logger->error('Something went wrong', ['user_id' => 5]);

Both Will send the following message to your mattermost channel: error-message.png

Warning: When you log to the mattermost channel make sure that the level is greater than or equals the one defined in config/logging.php

About

This package includes Mattermost drivers for Laravel different features like logging and notifications

License:MIT License


Languages

Language:PHP 100.0%