PHPackages                             bitbirddev/microsoft-teams-monolog-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. bitbirddev/microsoft-teams-monolog-handler

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

bitbirddev/microsoft-teams-monolog-handler
==========================================

Monolog handler sending Microsoft Teams notifications with an Incoming Webhook

1.0(2y ago)03.7kMITPHPPHP ^8.1

Since Dec 6Pushed 2y agoCompare

[ Source](https://github.com/bitbirddev/microsoft-teams-monolog-handler)[ Packagist](https://packagist.org/packages/bitbirddev/microsoft-teams-monolog-handler)[ Docs](https://github.com/bitbirddev/microsoft-teams-monolog-handler)[ RSS](/packages/bitbirddev-microsoft-teams-monolog-handler/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

bitbirddev Microsoft Teams Monolog Handler
==========================================

[](#bitbirddev-microsoft-teams-monolog-handler)

[![Package Version](https://camo.githubusercontent.com/69044af3c98c57461e5b5b9704929da6fd116b5f0b3dbbdf13548b84cc85ba7d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e322e302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/69044af3c98c57461e5b5b9704929da6fd116b5f0b3dbbdf13548b84cc85ba7d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e322e302d627269676874677265656e2e737667)

A PHP package that defines custom Monolog handler to send Microsoft Teams notifications with an Incoming Webhook. The package aims to provide global messaging &amp; log system that uses Microsoft Teams "MessageCard" notification and uses Monolog logging library.

Features
========

[](#features)

- Monolog wiring with Microsoft Teams channel
- Application error notifying
- Simple messaging

Install
=======

[](#install)

```
$ composer require bitbirddev/microsoft-teams-monolog-handler
```

Please consider running `composer suggest` command to install required and missing dependencies related to framework you use (ex. Symfony):

```
$ composer suggest
bitbirddev/microsoft-teams-monolog-handler suggests:
 - symfony/monolog-bundle: The MonologBundle provides integration of the Monolog library into the Symfony framework.
```

Microsoft Teams Webhook setting
===============================

[](#microsoft-teams-webhook-setting)

Follow these steps to set up new Webhook:

- In Microsoft Teams, choose More options (⋯) next to the channel name and then choose 'Connectors'
- Find in the list of Connectors the 'Incoming Webhook' option, and choose 'Add'
- Provide required information for the new Webhook
- Copy the Webhook url - that information will be used to configure the package with `MICROSOFT_TEAMS_WEBHOOK_URL`

Symfony configuration
=====================

[](#symfony-configuration)

Place the code below in `.env` file:

```
###> bitbirddev/microsoft-teams-monolog-handler ###
MICROSOFT_TEAMS_WEBHOOK_URL=webhook_url (without https://)
###< bitbirddev/microsoft-teams-monolog-handler ###
```

Register `MicrosoftTeamsMonologHandler.php` as a new service with the code below:

```
// config\services.yaml

services:
    ...

    # MICROSOFT TEAMS MONOLOG HANDLER
+    ms_teams_monolog_handler:
+        class: bitbirddev\MicrosoftTeamsNotifier\Handler\MicrosoftTeamsHandler
+        arguments:
+            $webhookDsn: '%https://env(MICROSOFT_TEAMS_WEBHOOK_URL)%'
+            $level: 'error'
+            $title: 'Message title'
+            $subject: 'Message subject'
+            $emoji:  '&#x1F6A8'
+            $color: '#fd0404'
+            $format: '[%%datetime%%] %%channel%%.%%level_name%%: %%message%%'
```

> *$webhookDsn:*
> Microsoft Teams webhook url
>
> *$level:*
> the minimum level for handler to be triggered and the message be logged in the channel (Monolog/Logger class: ‘error’ = 400)
>
> *$title (nullable):*
> title of Microsoft Teams Message
>
> *$subject (nullable):*
> subject of Microsoft Teams Message
>
> *$emoji (nullable):*
> emoji of Microsoft Teams Message (displayed next to the message title). Value needs to reflect the pattern: ‘&amp;#x&lt;EMOJI\_HEX\_CODE&gt;’
>
> *$color (nullable):*
> hexadecimal color value for Message Card color theme
>
> *$format (nullable):*
> every handler uses a Formatter to format the record before logging it. This attribute can be set to overwrite default log message (available options: %datetime% | %extra.token% | %channel% | %level\_name% | %message%).

Modify your Monolog settings that will point from now to the new handler:

```
// config\packages\dev\monolog.yaml
// config\packages\prod\monolog.yaml

monolog:
    handlers:
        ...

        # MICROSOFT TEAMS HANDLER
+        teams:
+            type: service
+            id: ms_teams_monolog_handler
```

> *type:*
> handler type (in our case this references custom notifier service)
>
> *id:*
> notifier service class \\bitbirddev\\MicrosoftTeamsNotifier\\LogMonolog

Laravel configuration
=====================

[](#laravel-configuration)

Place the code below in `.env` file:

```
###> bitbirddev/microsoft-teams-monolog-handler ###
MICROSOFT_TEAMS_WEBHOOK_URL=webhook_url (without https://)
###< bitbirddev/microsoft-teams-monolog-handler ###
```

Modify your Monolog logging settings that will point to the new handler:

### Att: definition of ALL parameters is compulsory - please use NULL value for attributes you want to skip.

[](#att-definition-of-all-parameters-is-compulsory---please-use-null-value-for-attributes-you-want-to-skip)

```
// config\logging.php
