actived/microsoft-teams-notifier
最新稳定版本:V1.3.0
Composer 安装命令:
composer require actived/microsoft-teams-notifier
包简介
Monolog handler sending Microsoft Teams notifications with an Incoming Webhook
README 文档
README
A PHP package that defines custom Monolog handler to send Microsoft Teams notifications with an Incoming Webhook. The package aims to provide global messaging & log system that uses Microsoft Teams "MessageCard" notification and uses Monolog logging library.
Features
- Monolog wiring with Microsoft Teams channel
- Application error notifying
- Simple messaging
Install
$ composer require actived/microsoft-teams-notifier
Since version 1.1 of the package, "symfony/monolog-bundle" was removed and replaced with "monolog/monolog" dependency that makes Actived Microsoft Teams Notifier more flexible for global use:
Please consider running composer suggest command to install required and missing dependencies related to framework you use (ex. Symfony):
$ composer suggest actived/microsoft-teams-notifier suggests: - symfony/monolog-bundle: The MonologBundle provides integration of the Monolog library into the Symfony framework.
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
ACTIVED_MS_TEAMS_DSN
Symfony configuration
Place the code below in .env file:
###> actived/microsoft-teams-notifier ### ACTIVED_MS_TEAMS_DSN=webhook_dsn ###< actived/microsoft-teams-notifier ###
Register ActivedMicrosoftTeamsHandler.php as a new service with the code below:
// config\services.yaml
services:
...
# ACTIVED MICROSOFT TEAMS NOTIFIER
+ actived_ms_teams_handler:
+ class: Actived\MicrosoftTeamsNotifier\Handler\MicrosoftTeamsHandler
+ arguments:
+ $webhookDsn: '%env(ACTIVED_MS_TEAMS_DSN)%'
+ $level: 'error'
+ $title: 'Message title'
+ $subject: 'Message subject'
+ $emoji: '🚨'
+ $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: ‘&#x<EMOJI_HEX_CODE>’$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:
...
# ACTIVED MICROSOFT TEAMS NOTIFIER
+ teams:
+ type: service
+ id: actived_ms_teams_handler
type:
handler type (in our case this references custom notifier service)id:
notifier service class \Actived\MicrosoftTeamsNotifier\LogMonolog
Laravel configuration
Place the code below in .env file:
###> actived/microsoft-teams-notifier ### ACTIVED_MS_TEAMS_DSN=webhook_dsn ###< actived/microsoft-teams-notifier ###
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.
// config\logging.php
<?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
'channels' => [
'stack' => [
'driver' => 'stack',
- 'channels' => ['single'],
+ 'channels' => ['single', 'custom'],
'ignore_exceptions' => false
],
# ACTIVED MICROSOFT TEAMS NOTIFIER
+ 'custom' => [
+ 'driver' => 'custom',
+ 'via' => \Actived\MicrosoftTeamsNotifier\LogMonolog::class,
+ 'webhookDsn' => env('ACTIVED_MS_TEAMS_DSN'),
+ 'level' => env('LOG_LEVEL', 'debug'), // or simply 'debug'
+ 'title' => 'Message Title', // can be NULL
+ 'subject' => 'Message Subject', // can be NULL
+ 'emoji' => '🏁', // can be NULL
+ 'color' => '#fd0404', // can be NULL
+ 'format' => '[%datetime%] %channel%.%level_name%: %message%' // can be NULL
+ ],
...
driver:
is a crucial part of each channel that defines how and where the log message is recorded. The ‘custom’ driver calls a specified factory to create a channel.via:
factory class which will be invoked to create the Monolog instancewebhookDsn:
Microsoft Teams webhook urllevel:
the minimum level for handler to be triggered and the message be logged in the channel (Monolog/Logger class: ‘debug’ = 100)title (nullable):
title of Microsoft Teams Messagesubject (nullable):
subject of Microsoft Teams Messageemoji (nullable):
emoji of Microsoft Teams Message (displayed next to the message title). Value needs to reflect the pattern: ‘&#x<EMOJI_HEX_CODE>’color (nullable):
hexadecimal color value for Message Card color themeformat (nullable):
message template - available options: %datetime% | %extra.token% | %channel% | %level_name% | %message%
Usage
Correctly configured service in Symfony/Laravel will raise Logs in Microsoft Teams automatically accordingly to level assigned to.
Symfony - manual messaging
// LoggerInterface $logger $logger->info('Info message with custom Handler'); $logger->error('Error message with custom Handler');
Laravel - manual messaging
// Illuminate\Support\Facades\Log Log::channel('custom')->info('Info message with custom Handler'); Log::channel('custom')->error('Error message with custom Handler');
License
The code is available under the MIT license. See the LICENSE file for more info.
actived/microsoft-teams-notifier 适用场景与选型建议
actived/microsoft-teams-notifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 354.31k 次下载、GitHub Stars 达 14, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「monolog」 「notifier」 「microsoft」 「webhook」 「Teams」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 actived/microsoft-teams-notifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 actived/microsoft-teams-notifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 actived/microsoft-teams-notifier 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
Symfony JustCall Notifier Bridge
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
统计信息
- 总下载量: 354.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 47
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 未知