PHP code example of carpediem / mattermost-monolog

1. Go to this page and download the library: Download carpediem/mattermost-monolog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

carpediem / mattermost-monolog example snippets




arpediem\Mattermost;
use GuzzleHttp\Client as GuzzleClient;
use Monolog\Logger;

$template = (new Mattermost\Webhook\Message('This text will be overriden by the logger'))
    ->setChannel('alerts')
    ->setUsername('AlertBot')
    ->setIconUrl('https://cdn2.iconfinder.com/data/icons/security-2-1/512/bug-512.png')
;

$monolog_handler = new Mattermost\Monolog\Handler(
    'https://your_mattermost_webhook_url',
    new Mattermost\Webhook\Client(new GuzzleClient(['http_errors' => false]))
    Logger::WARNING
);
$monolog_handler->setFormatter(new Mattermost\Monolog\Formatter($template));

$logger = new Logger('MyAwesomeLogger');
$logger->pushHandler($monolog_handler);