Skip to content

Latest commit

 

History

History
91 lines (71 loc) · 2.25 KB

README.md

File metadata and controls

91 lines (71 loc) · 2.25 KB

Monolog Microsoft Teams

Package Version Packagist Version

A Monolog handler to send Microsoft Teams messages via the Incoming Webhook.

Features

Send text messages to the incoming webhook of microsoft teams with different theme colors based on the log level. All this whilst using the well known monolog library as backbone!

Install

composer require rspeekenbrink/monolog-microsoft-teams

Usage

<?php

use Monolog\Logger;
use Rspeekenbrink\MonologMicrosoftTeams\MicrosoftTeamsHandler;

// create a log channel
$log = new Logger('microsoft-teams-logger');
$log->pushHandler(new MicrosoftTeamsHandler(
    'YOUR_WEBHOOK_URL',
    'Fancy Title',
    Logger::WARNING
));

// add records to the log
$log->warning('Foo');
$log->error('Bar');

or

<?php

use Rspeekenbrink\MonologMicrosoftTeams\MicrosoftTeamsLogger;

// create a log channel
$log = new MicrosoftTeamsLogger(
    'YOUR_WEBHOOK_URL',
    'Fancy Title',
    Logger::WARNING
);

// add records to the log
$log->warning('Foo');
$log->error('Bar');

Usage with Laravel/Lumen framework

From Laravel/Lumen 5.6+ you can easily use custom drivers for logging. First create a Custom Channel.

in config/logging.php add:

'teams' => [
    'driver' => 'custom',
    'via' => \Rspeekenbrink\MonologMicrosoftTeams\MicrosoftTeamsChannel::class,
    'level' => 'error',
    'url' => env('LOG_TEAMS_WEBHOOK_URL'),
    'title' => 'My Application'
],

then in your .env file add:

LOG_TEAMS_WEBHOOK_URL=YOUR_WEBHOOK_URL

Send error messages via the Log facade to the teams channel:

\Log::channel('teams')->error('Oh Snap, Stuff broke again!');

Or add the teams channel to the default stack channel in config/logging.php:

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

License

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