rspeekenbrink/monolog-microsoft-teams

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

1.1.0 2019-04-16 15:41 UTC

This package is auto-updated.

Last update: 2024-11-06 20:50:38 UTC


README

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.