I'm trying to set up a console command in Symfony2 so that it logs to the console in my dev environment, but to a logfile in prod.
so my config_prod.yml has this:
monolog:
handlers:
payment:
type: stream
path: %kernel.logs_dir%/payment.log
channels: payment
while my config_dev.yml uses this:
monolog:
handlers:
console:
type: console
channels: payment
and the service is defined in services.yml like this:
payment_manager:
class: My\Bundle\Service\PaymentManager
arguments: [#doctrine.orm.entity_manager, #logger]
tags:
- { name: monolog.logger, channel: payment }
To my surprise, this does squat nothing. Output goes to app/logs/dev.log instead of the console. Why?
It turns out that "console" doesn't actually mean console at all, it means "browser's javascript console".
If you came here because you have the same question, here's how to do it:
output:
type: stream
path: php://stdout
level: info
Related
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.
The setup is thus:
I have a command, which calls a function on service X which uses logger Y.
Currently, when run from the console, the log messages are output to the console (using the -v parameters). I would also like to output those messages to a file, regardless of the -v level.
Edit: Adding monolog config, as requested (though there's nothing interesting - it's the default).
monolog:
channels: ['amz_update']
handlers:
main:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: emergency
channels: ['!event']
console:
type: console
process_psr_3_messages: false
channels: ['!event', '!doctrine', '!console']
# To follow logs in real time, execute the following command:
# `bin/console server:log -vv`
server_log:
type: server_log
process_psr_3_messages: false
host: 127.0.0.1:9911
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.
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"]