【问题标题】:Configure symfony monolog to keep apache logs配置 symfony monolog 保留 apache 日志
【发布时间】:2015-03-24 19:29:03
【问题描述】:

我在 Symfony 2 中使用以下 Monolog 配置在 /app/logs/ 目录中的文件中记录较小的错误,并针对所有严重错误发送电子邮件。

monolog:
    handlers:
        main:
            level: error
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_remaining.log"
            channels: ["!doctrine", "!request", "!security"]
        request:
            type: fingers_crossed
            handler: requests
        requests:
            type:    group
            members: [request_critical, request_error]
        request_critical:
            level: critical
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_request_critical.log"
            channels: [request]
        request_error:
            level: error
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_request.log"
            channels: [request]
        doctrine:
            level: error
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_doctrine.log"
            channels: [doctrine]
        security:
            level: error
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%_security.log"
            channels: [security]
        mail:
            type: fingers_crossed
            action_level: critical
            handler: buffered
        buffered:
            type: buffer
            handler: swift
        swift:
            type: swift_mailer
            from_email: "%mailer_from_address%"
            to_email:   "%development_address%"
            subject:    A critical error occurred

我的问题是,这个设置似乎阻止了 Apache 在虚拟主机配置中设置的本机日志记录:

<VirtualHost *:80>        
        <Directory "/mnt/vm/vm.healthcare-cpd/web">
           Header set Access-Control-Allow-Origin "*"
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           Allow from all
           Require all granted
        </Directory>

        php_flag log_errors on
        php_value error_reporting 2147483647

        ErrorLog ${APACHE_LOG_DIR}/vm.healthcare-cpd.error.log
        CustomLog ${APACHE_LOG_DIR}/vm.healthcare-cpd.access.log combined
        php_value error_log ${APACHE_LOG_DIR}/vm.healthcare-cpd.php.error.log
</VirtualHost>

${APACHE_LOG_DIR}/vm.healthcare-cpd.error.log和{APACHE_LOG_DIR}/vm.healthcare-cpd.php.error.log文件为空,我认为是Monolog造成的。

所以我的问题是:如何在 Symfony 2 中配置 Monolog,以便 Apache 和 PHP 日志仍然与 Monolog 日志并行工作?

【问题讨论】:

    标签: php apache symfony monolog


    【解决方案1】:

    Apache 的错误日志与你的应用程序日志(Monolog)无关。

    这里的问题是,如果您通过在 php 代码中捕获 php 错误或异常来处理错误,或者如果 Symfony 捕获这些错误并将它们转换为正确的响应(实际上它确实如此),Apache 将永远不会知道某些事情失败了,因此不会在其错误日志中记录任何内容。

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2019-08-07
      • 2015-05-06
      • 1970-01-01
      • 2018-12-20
      • 2023-03-11
      • 1970-01-01
      • 2020-08-11
      • 2016-08-22
      相关资源
      最近更新 更多