Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure symfony monolog to keep apache logs

I'm using the below Monolog configuration in Symfony 2 to log lesser errors in files in the /app/logs/ directory and send emails for all critical errors.

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

My problem is that it appears this setup is preventing Apache's native logging set in the Virtual Host config:

<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>

The ${APACHE_LOG_DIR}/vm.healthcare-cpd.error.log and {APACHE_LOG_DIR}/vm.healthcare-cpd.php.error.logfiles are empty, which I believe to be caused by Monolog.

So my question is: how to configure Monolog in Symfony 2 so that Apache and PHP logging are still working in parallel with Monolog logging?

like image 590
trajan Avatar asked Jan 26 '15 11:01

trajan


1 Answers

Apache's error log has nothing to do with your application log (Monolog).

The issue here is that if you handle errors by catching php errors or exceptions in your php code or if Symfony catches those and transform them to a proper response (which it in fact does) Apache will never know that something failed and therefore does not log anything to its error log.

like image 194
Zerrvox Avatar answered Sep 21 '22 05:09

Zerrvox