Skip to content

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

License

Notifications You must be signed in to change notification settings

RSpeekenbrink/monolog-microsoft-teams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages