禁用登录 Symfony2

Tej*_*sai 4 symfony

这个问题以前可能有人问过。我已经搜索了答案,但我还没有找到我想要的。

在 Symfony 2.3 中,有没有办法针对特定请求禁用记录器?我的意思是,我正在为我的项目使用 SOAP 服务。当我发送登录请求时,用户名和密码作为纯文本直接转储到日志文件中。有没有办法停止记录此类特定请求?

例如,当我发送登录请求时,记录器应该被禁用,但对于所有其他请求,它会再次工作。这可能吗?

Cha*_*nel 5

取决于您是在 Prod 还是 Dev 环境中,但一切都在 config.yml 或 config_dev.yml 中:

要禁用日志记录,只需删除像这样的 monolog 配置:

monolog:
  handlers:
    main:
        type:   stream
        path:   "%kernel.logs_dir%/%kernel.environment%.log"
        level:  debug
    console:
        type:   console
        bubble: false
    # uncomment to get logging in your browser
    # you may have to allow bigger header sizes in your Web server configuration
    #firephp:
    #    type:   firephp
    #    level:  info
    #chromephp:
    #    type:   chromephp
    #    level:  info
Run Code Online (Sandbox Code Playgroud)

但在我看来,你不应该这样做,因为日志记录可以让你显着改进你的代码!

除特定服务外的日志记录:

您需要为您的服务创建一个特定的日志通道,如下所述:http : //symfony.com/doc/current/cookbook/logging/channels_handlers.html 和那里:http : //symfony.com/doc/current/reference /dic_tags.html#dic-tags-monolog

您将能够将您的肥皂日志与其他人分开并最终将其发送到 null