Symfony生产环境日志

7
在Symfony 3中,是否有任何方法可以在生产环境中将所有错误写入日志文件而无需设置调试模式?这些错误包括HTTP 500错误、应用程序错误或由于在生产环境中将错误标志设置为false而被静音的PHP错误。
当前的生产环境日志配置为:
monolog:
    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: info
            channels: [!request, !event, !translation, !kernel, !security, !php, !snc_redis]
       php:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_php.log"
            level: warning
            channels: [php]
1个回答

11
您可以使用默认的生产环境设置(取自monolog-bundle recipe)来完成此操作:
monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: nested
            excluded_404s:
                # regex: exclude all 404 errors from the logs
                - ^/
        nested:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug

这种配置的作用是Monolog在请求期间缓冲所有消息,但只有在出现错误时才将它们写入日志。这样,您就不会一直在日志中看到嘈杂的调试和信息消息。只有在请求期间出现错误时,才能获得完整的日志信息。


谢谢,这很有用。我会试一下并反馈。另外,“excluded_404s”是一个自定义参数名称,对吗?那么我也可以创建一个“excluded_localhost”,使用模式例如“(127.0.0.1) (ignore pattern)”作为额外的排除条件? - N Kiran Kumar Kowlgi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接