Monolog 没有写入正确的日志文件

Monolog doesn't write to the right log file

我在使用 Symfony 4,我想为许多日志类型创建一个专用通道: 这是我的通道和处理程序配置:

 monolog:
  channels: ["channel1", "channel2"]

  handlers:
    channel1:
      level: debug
      type:  stream
      path:  "%kernel.logs_dir%/channel1.log"
      channels: ["channel"]

    channel2:
      level: debug
      type:  stream
      path:  "%kernel.logs_dir%/channel2.log"
      channels: ["channel2"]

然后,在我写日志的服务中,我注入了自定义

 services:
  _defaults:
    autowire: true
    autoconfigure: true
  Infrastructure\Logger\Channel1Logger:
    arguments:
       - '@monolog.logger.channel1'

  Infrastructure\Logger\Channel2Logger:
    arguments:
      - '@monolog.logger.channel2'

但是,我所有的日志都是直接写到频道"app", 当我调试容器时,我看到列出了我的服务 我做错了什么?

我发现了错误。默认情况下,config/services.yaml 将覆盖来自外部文件的所有配置。这就是为什么我的日志继续在默认频道(自动装配)上的原因。为避免这种情况,您必须从自动装配中排除记录器自定义文件