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

来源:互联网 发布:2016餐饮行业数据分析 编辑:程序博客网 时间:2024/06/11 18:41

监听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 文件

<?phpnamespace 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']);  }}
0 0
原创粉丝点击