ssswang/monolog-microsoft-teams

Monolog Handler for sending messages to Microsoft Teams using the Incoming Webhook connector

v5.0.0 2024-07-17 17:44 UTC

This package is auto-updated.

Last update: 2024-11-22 18:47:48 UTC


README

Monolog Handler for sending messages to Microsoft Teams channels using the Incoming WebHook connector.

Install

$ composer require ssswang/monolog-microsoft-teams

Usage

You need webhook_url from Teams and also set mininum level of log message to be sent

$logger = new \Monolog\Logger('app');
$logger->pushHandler(new \MonologMicrosoftTeams\TeamsLogHandler(env('TEAMS_WEBHOOK_URL'), \Monolog\Logger::ERROR));

Usage with Laravel 5.4~5.5

$monolog = \Log::getMonolog();
$teamsHandler = new \MonologMicrosoftTeams\TeamsLogHandler(env('TEAMS_WEBHOOK_URL'), \Monolog\Logger::NOTICE);
$monolog->pushHandler($teamsHandler);

Usage with Laravel/Lumen framework (5.6+)

Create a custom channel

config/logging.php

'teams' => [
    'driver' => 'custom',
    'via' => \MonologMicrosoftTeams\TeamsLogChannel::class,
    'level' => 'error',
    'url' => 'INCOMING_WEBHOOK_URL',
],

Send an error message to the teams channel:

Log::channel('teams')->error('Error message\n\nDouble slash n To start new line.');

You can also add teams to the default stack channel so all errors are automatically send to the teams channel.

'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'teams'],
    ],
],

License

monolog-microsoft-teams is available under the MIT license. See the LICENSE file for more info.