配置symfony monolog以保留apache日志

时间:2015-01-26 11:27:36

标签: php apache symfony monolog

我在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日志记录并行工作?

1 个答案:

答案 0 :(得分:2)

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

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