监听Symfony日志 将500错误发送到微信

    xiaoxiao2021-03-25  79

    监听Symfony日志 将500错误发送到微信

    编辑 app/config/config.yml 文件

    monolog: handlers: wecaht: type: fingers_crossed action_level: critical //Monolog\logger::CRITICAL handler: wecaht_handler

    编辑 app/config/services.yml 文件

    services: ...... monolog.handler.wecaht_handler: class: AppBundle\Event\MonologHandler arguments: ['@wechatService']

    创建 AppBundle\Event\MonologHandler 文件

    <?php namespace AppBundle\Event; use Monolog\Logger; use Monolog\Formatter\JsonFormatter; use Monolog\Handler\AbstractProcessingHandler; use AppBundle\Services\WechatService; class MonologHandler extends AbstractProcessingHandler { private $_wechat; public function __construct(wechatService $wechat, $level = Logger::CRITICAL, $bubble = true) { parent::__construct($level, $bubble); parent::setFormatter(new JsonFormatter()); } protected function write(array $record) { //请参考微信开发文档,使用微信企业号用来接收通知 $this->_wechat->sendNotify($toUser, $record['formatted']); } }
    转载请注明原文地址: https://ju.6miu.com/read-16030.html

    最新回复(0)