繁体   English   中英

symfony monolog根据通道将日志写入不同的文件

[英]symfony monolog writing logs to different files according to channels

在我的Symfony应用中,我使用独白记录错误,并且获得了不同的渠道。 我需要将不同的通道写入不同的文件。 我得到以下monolog配置:

//app\config\config.yml
monolog:
channels: ['my_channel', 'my_channel2']
use_microseconds: false
handlers:
    file:
        type:   stream
        path:   %kernel.logs_dir%/prod_info.log
        level:  info
        channels: [!my_channel2]
    file_2:
        type:   stream
        path:   %kernel.logs_dir%/mylogfile_2.log
        level:  info
        channels: [my_channel2]
    file_errors:
        type:   stream
        path:   %kernel.logs_dir%/cms_errors.log
        level:  error
        channels: [!my_channel2]

我的config.prod配置

monolog:
handlers:
    main:
        type:         fingers_crossed
        action_level: debug
        handler:      nested
        channels: [!my_channel2]
    nested:
        type:  stream
        path:  "%kernel.logs_dir%/main_%kernel.environment%.log"
        level: debug
        channels: [!my_channel2]
    console:
        type:  console

我可以通过my_channel2代码访问my_channel2

$logger = $this->get('monolog.logger.my_channel2');
$logger->debug('Some message here');

但仍然是所有my_channel2消息都写入main_prod.log文件,而不是mylogfile_2.log 任何想法如何解决它都将受到欢迎。 谢谢。

只需要将操作级别从信息更改为所需通道的调试

file_2:
    type:   stream
    path:   %kernel.logs_dir%/mylogfile_2.log
    level:  debug // <== change from info to debug here
    channels: [my_channel2]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM