我很难理解如何在我的 symfony 应用程序中配置日志记录来做我需要做的事情。我不明白处理程序和渠道之间的区别/关系。我有以下内容config.yml
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
dynamic_request:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%_dynamic.log"
level: debug
然后我在我的services.yml
jsonstub.dynamic.response_provider:
class: ProgrammingAreHard\JsonStub\CoreBundle\Domain\Dynamic\EventListener\DynamicResponseProvider
arguments:
- @security.context
- @logger
- %kernel.environment%
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onAuthentication }
- { name: monolog.logger, channel: dynamic_request }
所需的行为是仅 error
记录日志%kernel.logs_dir%/%kernel.environment%.log
,然后我想将记录器注入到我DynamicResponseProvider
的日志中%kernel.logs_dir%/%kernel.environment%_dynamic.log
。文档让我很困惑。它声明如下:
configuration defines a stack of handlers which will be called in the order where they are defined
这是否意味着因为我dynamic_request
定义了处理程序,所以任何调试日志都将记录在这里?那不是我想要的行为。我想要的是只有DynamicResponseProvider
将使用该处理程序。我怎样才能做到这一点?