在我的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
:
$logger = $this->get('monolog.logger.my_channel2');
$logger->debug('Some message here');
但仍将所有my_channel2
消息而不是main_prod.log
写入mylogfile_2.log
文件。任何想法如何解决它都将受到欢迎。谢谢。
答案 0 :(得分:0)
只需将操作级别从信息更改为所需通道的调试
file_2:
type: stream
path: %kernel.logs_dir%/mylogfile_2.log
level: debug // <== change from info to debug here
channels: [my_channel2]