【发布时间】:2016-07-15 16:12:45
【问题描述】:
我正在开发一个 Symfony 2 网络应用程序,我想使用特定通道向服务注入 Monolog 记录器:
配置:
monolog:
handlers:
main:
type: stream
path: %kernel.root_dir%/%kernel.environment%.log
level: error
#channels: [!alert]
alert:
type: stream
path: %kernel.root_dir%/%kernel.environment%.alert.log
level: info
channels: [alert]
服务配置:
services:
some_service:
class: Some\Service
arguments: [@logger]
tags:
- { name: monolog.logger, channel: alert }
服务:
class SomeService {
protected $logger;
public function __construct($logger) {
$this->logger = $logger;
$this->logger->info('Log this!');
}
prod.log 文件:
[2016-03-28 11:25:47] alert.INFO:记录这个!
问题:虽然我专门使用alert 通道注入记录器,但消息由main 处理程序处理。因此,消息被记录到prod.log 文件而不是prod.alert.log 文件中。
当我将channels: [!alert] 行作为注释时,该消息将记录到prod.log。当我通过删除注释激活此行时,根本不会记录该消息(主处理程序正确忽略了通道)。
为了使用特定的处理程序来定位特定的日志文件、邮件程序等,我需要做什么? alert 频道的消息应该由alert 处理程序处理,而所有其他处理程序都被忽略。
【问题讨论】: