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.log
files 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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With