Monolog Handler for sending messages to Microsoft Teams channels using the Incoming WebHook connector.
$ composer require ssswang/monolog-microsoft-teams
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));
$monolog = \Log::getMonolog();
$teamsHandler = new \MonologMicrosoftTeams\TeamsLogHandler(env('TEAMS_WEBHOOK_URL'), \Monolog\Logger::NOTICE);
$monolog->pushHandler($teamsHandler);
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'],
],
],
monolog-microsoft-teams is available under the MIT license. See the LICENSE file for more info.