编辑 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']); } }