apollo11/yii2-logger

在 Slack 频道中记录应用程序错误

安装次数: 7,503

依赖项: 0

建议者: 0

安全性: 0

星星: 10

关注者: 8

分支: 2

开放问题: 4

类型:yii2-extension

v1.3.0 2018-10-22 11:31 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:08:16 UTC


README

将 Yii2 应用程序的日志异步或同步发送到不同的目标。

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

php composer.phar require --prefer-dist apollo11/yii2-logger "~1.0"

或者

"apollo11/yii2-logger": "~1.0"

将以下内容添加到您的 composer.json 文件的 require 部分。

该软件包提供以下功能:

  1. 抽象的 Target 类,支持异步发送消息。它还可以在将 $_POST 或其他 $GLOBALS 数据发送到目标时隐藏敏感信息。
  2. Slack 目标:将消息发送到 Slack 频道

基本用法

该软件包支持三种目标类:EmailTargetSlackTargetDbTarget

所有目标类都支持异步发送消息并隐藏用户提供的密码(或其他敏感数据)。如果您将 async 设置为 true,则必须提供 consoleAppPath

EmailTarget 和 DbTarget 的工作方式与 Yii 文档 中描述的相似。

将以下代码添加到您的项目配置文件中的 components -> log -> targets

'class' => <Target class>,
// If async is set to true you have to provide consoleAppPath
'async' => true,
'consoleAppPath' => Yii::getAlias('@console/yii'),
// If you would like to use different php binary, when sending messages asynchronously you can set it from here
// 'phpExecPath' => 'php',
// Provide here keys which will be hidden before sending messages. It is case insensitive
'excludeKeys' => [
    '*PASSWORD*', // Will hide all keys from $GLOBALS objects which contains "password".
    '*PASSWORD', // Will hide all keys from $GLOBALS objects which ends with "password".
    'PASSWORD*', // Will hide all keys from $GLOBALS objects which starts with "password".
],

SlackTarget

'class' => apollo11\logger\SlackTarget::class,
'except' => ['yii\web\HttpException:*', 'yii\web\HeadersAlreadySentException'],
'webhookUrl' => <Slack channel webhook url>,
'icon_url' => '<Slack sender icon url>',
'icon_emoji' => '<Slack sender icon emoji>', // If both, icon_url and icon_emoji is provided system will use icon_emoji
'levels' => ['error', 'warning'],
'title_link' => '<Url which will be opened when clicking on title of the slack message>',
'async' => true,
'consoleAppPath' => Yii::getAlias('@console/yii'),
'username' => '<Username which will be used as sender on slack channer>',
'excludeKeys' => [],

重要

如果您将 async 属性设置为 true,则必须在您的控制台应用程序的 controllerMap 中添加以下代码。

'async' => [
    'class' => \apollo11\logger\AsyncController::class,
],