我很难理解如何在我的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
将使用该处理程序。我怎样才能实现这一目标?
答案 0 :(得分:1)
您可以为处理程序指定通道。 因此,如果您希望'dynamic_request'处理程序仅用于'dynamic_request'日志,则config.yml必须是:
dynamic_request:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%_dynamic.log"
level: debug
channels: dynamic_request
有关更多示例,请参阅http://symfony.com/doc/current/cookbook/logging/channels_handlers.html