I have configured my app to send emails on exceptions this way (prod/monolog.yaml):
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: grouped
excluded_404s:
# regex: exclude all 404 errors from the logs
- ^/
grouped:
type: group
members: [nested, deduplicated]
deduplicated:
type: deduplication
handler: swift
swift:
type: swift_mailer
from_email: '%admin_notifier_from%'
to_email: '%admin_notifier_to%'
subject: 'Error'
level: debug
formatter: monolog.formatter.html
content_type: text/html
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
And it works. When I throw an exception in some controller, open url for that controller I get an email with an exception. So emailing works on http level. However it does not on console level. I am using SF v4.2. I found that in recent symfony version console exception logging was added so no need to add error console listener for it. It should work on my version. Actually I see exception messages in log files. But no email. So I decided to add an error listener and log critical message (assuming it should trigger main monolog handler). So I did it. And again, I see my critical message in log file but still no email. So what wrong am I doing? I want to get exception emails on console exceptions.
I triend to replace "deduplicated" handler with "swift" one but it did not help.
Related
In our Symfony 3 app all logging from console commands (e.g. when there's an exception) are nicely formatted and displayed to the screen... which when dealing with cron jobs in production mode is completely useless.
All exception logging from HTTP requests are routed through log files on the server and reports sent to us via Swifmail (as per https://symfony.com/doc/3.4/logging/monolog_email.html)
I need to get logs from console commands treated the same as logs from HTTP requests but the Symfony documentation seems to ignore this scenario?
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
grouped:
type: group
members: [streamed, deduplicated]
streamed:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
deduplicated:
type: deduplication
handler: swift
swift:
type: swift_mailer
level: debug
formatter: monolog.formatter.html
content_type: text/html
console:
type: console
process_psr_3_messages: false
Any ideas?????
-- Edit --
It turns out that Symfony logs console exceptions at Monolog's error(400) level but we have monolog.handlers.main.action_level set to critical(500).
So, it seems, that I can either patch Symfony\Component\Console\EventListener\ErrorListener to call $this->logger->addCritical instead of $this->logger->error or take the config level down from critical to error and put up with getting error reports for all the HTTP 4?? errors too.
I am getting a generic error ("Authentication request could not be processed due to a system problem") while logging in. I understand that the reasons could be numerous, but I am getting nothing in the prod logs. How do I get an message in the log files or alternately, how can I debug this? I am testing against my local environment and so have access to everything. I have deleted all cache(s)
Below is my config_prod.yaml
imports:
- { resource: config.yml }
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
level: info
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
I can get the logs and with it the reason for the failure once I set the action level in the monolog above to "info":
action_level: info
Still, it is quite remarkable that a fatal error disallowing the application from starting is logged by symfony with mere "info" severity.
W have web-app, built with symfony-flex. For deployment, I am using capistrano. For logging critical logs, I have configured monolog in this way:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
channels: ['!translation']
excluded_http_codes: [{ 404: ['^/security/login'] }]
handler: grouped
grouped:
type: group
members: [deduplicated]
deduplicated:
type: deduplication
handler: swift
swift:
type: swift_mailer
from_email: '%mailer_user%'
to_email: ['email1#gmail.com', 'email2#gmail.com']
subject: "📞🚨 %%level_name%% %%level%%"
level: info
formatter: monolog.formatter.html
content_type: text/html
SwiftMailer configuration:
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
And all works fine except logs after each release. I'm getting old logs which were sent before. Example:
Maybe i have missed something in configuration?
The MonologBundle configuration for the deduplication handler type has additional potential parameters - including
store: The file/path where the deduplication log should be kept, defaults to %kernel.cache_dir%/monolog_dedup_*
It is re-reading the file that is in the cache directory from before you deployed.
I also deploy my site(s) with Capistrano - but I do not share the cache directory between different deploys of my site. My config for shared files is set :linked_dirs, [fetch(:log_path)] - only shares the logs to keep updating them in the long term. The cache directory is still in ./var/cache, but it's freshly created on each deployment.
I wanted to add a new block in my monolog config in order to have logs of a specific bundle in a separate log file. Say that the channel is called purchase
config_dev.php / config_prod.php
purchase:
type: rotating_file
max_files: 10
path: %kernel.logs_dir%/purchase_%kernel.environment%.log
level: debug
channels: purchase
In dev mode, every thing works great and the puchase logs are written in purchase_dev.log. However, although the log configuration of prod mode is the same as dev mode, I'm getting this error
Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' with message 'The service definition "monolog.logger.purchase" does not exist.' in /home/users/me/projects/ecoback/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:798
monolog:
channels: ["purchase"]
handlers:
purchase:
type: rotating_file
max_files: 10
path: %kernel.logs_dir%/purchase_%kernel.environment%.log
level: debug
channels: ["purchase"]
It's a painfull job to analyse my actual dev log because the huge amount of "event.DEBUG: Notified event ..." messages. Anyone knows how can I disable the dispatcher notification logs?
Thanks in advance!
You can use channels to ignore events.
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: "!event"
see details here : http://symfony.com/doc/current/cookbook/logging/channels_handlers.html#yaml-specification
The easiest way to accomplish all of this is splitting the various logging channels and levels in app/config/config_dev.yml
monolog:
handlers:
event_all:
bubble: false
action_level: DEBUG
type: stream
path: %kernel.logs_dir%/%kernel.environment%_event_all.log
channels: event
event_errors:
action_level: ERROR
type: stream
path: %kernel.logs_dir%/%kernel.environment%_event_errors.log
channels: event
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: DEBUG
Best guide for how to separate different channels and error levels is here:
http://symfony.com/doc/current/cookbook/logging/monolog.html
Also, see here for my personal recommendations for production log separation:
Symfony2 - Doctrine log