leovince / monolog-teams
Monolog handler for sending log messages to Microsoft Teams channels via Workflows.
v1.0.0
2026-05-06 06:23 UTC
Requires
- php: ^8.3
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- monolog/monolog: ^3.0
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- pestphp/pest: ^4.6
README
This package provides a Monolog handler that delivers log records to a Microsoft Teams channel by calling an HTTP endpoint generated by a Teams Workflow.
Installation
You can install the package via composer:
composer require leovince/monolog-teams
Configuring Workflows on Microsoft Teams
- In Microsoft Teams, open the Team that contains the channel intended to receive log messages.
- Add the Workflows app to the team if it is not already installed.
- Open the Workflows app and create a new workflow.
- Choose the template “Send webhook alerts to a channel”.
- When prompted, select the Team and Channel where messages should be posted.
- The workflow will generate a unique HTTP POST URL.
Usage
use LeoVince\MonologTeams\TeamsHandler; use Monolog\Level; use Monolog\Logger; // Create the logger $log = new Logger('my_logger'); $log->pushHandler(new TeamsHandler('WEBHOOK_URL', 'APP_NAME', level: Level::Error)); // Use the logger $log->error('Error message');
Usage with Laravel
Add to config/logging.php the following configuration under the channels key:
'teams' => [ 'driver' => 'monolog', 'handler' => LeoVince\MonologTeams\TeamsHandler::class, 'level' => env('LOG_LEVEL', 'error'), 'handler_with' => [ 'webhookUrl' => env('TEAMS_WEBHOOK_URL'), 'name' => env('APP_NAME', 'Laravel'), 'includeContextAndExtra' => true, ], ],
Add to .env the following variable:
TEAMS_WEBHOOK_URL=WEBHOOK_URL
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.