I constantly am seeing a bunch of the following log:
[2015-02-15 09:08:16] request.INFO: Matched route "AppMainBundle_daftar_toko_province" (parameters: "_controller": "App\MainBundle\Controller\ZHomepageController::daftarTokoAction", "provinceName": "DKI JAKARTA", "_route": "AppMainBundle_daftar_toko_province") [] []
[2015-02-15 09:08:16] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2015-02-15 09:08:16] security.DEBUG: Write SecurityContext in the session [] []
in my prod.log, how can I disable this and I just want to see the errors. Here is my monolog settings:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: file
excluded_404s:
- ^/items/
file:
type: stream
level: debug
doctrine:
action_level: debug
type: stream
path: %kernel.logs_dir%/doctrine_%kernel.environment%.log
channels: doctrine
You can define which channels to be logged. Use something like this to ignore a specific channel:
channels: ["!security"]
If you only want to ignore specific log levels you can use the
level param or use a combination of both in a new handler.
In symfony4(And maybe higher versions)
https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler
File: \config\packages\dev\monolog.yaml
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event", "!request", "!security"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console", "!request", "!security"]
In my config (WebServer) of symfony4.4 I had channels: ["!event", "!doctrine", "!console"] for Console and channels: ["!event"] for Main
Related
I am new to Symfony 5.3 and Monolog. The docu explains "the Symfony Framework organizes log messages into channels. By default, there are several channels, including doctrine, event, security, request and more."
Is there any way to find out what channels exactly are configured?
I tried to run php bin/console debug:config monolog but this only shows the channels I configured (e.g. by adding channels: ['myChannelA', 'channelB'] to the monolog.yaml)
I made no changes (beside adding custom channels, see above) to the default monolog config which was created on install:
// config/packages/dev/monolog.yaml
monolog:
channels: ['myChannelA','channelB']
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
// config/packages/prod/monolog.yaml
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: php://stderr
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
You can try the following command:
php bin/console debug:autowiring | grep monolog
I have a worker that needs to retry consuming some messages until an external service is available to store them, which is only available on work hours, but the events can be generated at any time.
Everything is working as expected, and I'm logging both stderr and stout for traceability purposes. This is a business decision and there's now way around it, so no .log files. But symfony messenger seems to be outputting massive amounts of data, mostly related to redelivery and delay stamps, and my logs are getting out of hand.
These outputs have no valuable information and seem to be serialized stamps. And there's thousands of them every hour:
:67:\\\"\\0Symfony\\\\Component\\\\Messenger\\\\Stamp\\\\RedeliveryStamp\\0...
:51:\\\"\\0Symfony\\\\Component\\\\Messenger\\\\Stamp\\\\DelayStamp\\0delay...
I have no custom middlewares and nothing is printed in my own code.
I tried configuring monolog to ignore messenger and doctrine related entries with no luck:
channels: ["!event", "!doctrine", "!messenger", "!security"]
This is what my messenger.yaml looks like:
framework:
messenger:
failure_transport: failed
transports:
failed: 'doctrine://default?queue_name=failed'
async:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
retry_strategy:
max_retries: 14400
delay: 300000
multiplier: 1
max_delay: 300000
options:
queue_name: redacted_queue_name
routing:
'App\Domain\UserCreatedEvent [async]
Am I missing some obvious way to disable this output?
Edit: this is what my monolog.yaml looks like:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
path: "php://stdout"
channels: ["!event", "!doctrine", "!messenger", "!security"]
nested:
type: stream
path: "php://stdout"
channels: ["!event", "!doctrine", "!messenger", "!security"]
console:
level: warning
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!messenger", "!security"]
deprecation:
type: stream
path: "php://stdout"
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: ["php"]
Is it possible to format the log for syslog? The config.yml configuring syslog:
monolog:
channels: ['auth']
handlers:
auth:
type: syslog
level: debug
facility: local0
channels: [auth]
The resulting line printed in case of a warning:
Sep 20 15:43:31 api2 [10227]: auth.WARNING: invalid password {"method":"ApiBundle\\Api.....
The line as I'd like to see:
Sep 20 15:43:31 api2 auth.WARNING[10227]: invalid password {"method":"ApiBundle\\Api.....
I tried to use a formatter with no luck:
# config.yml
monolog:
...
handlers:
auth:
...
formatter: monolog.formatter.auth_exception
# services.yml
monolog.formatter.auth_exception:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n"
In the end I used the following config:
# config.yml
monolog:
channels: ['weather', 'auth']
handlers:
main:
type: fingers_crossed
action_level: error
handler: syslog_handler
syslog_handler:
type: syslog
level: debug
console:
type: console
app:
type: syslog
level: debug
channels: ['weather']
auth:
type: syslog
level: warning
facility: auth
channels: [auth]
I noticed in the symfony logs in the Production Environment that i am getting the following entries:
[2017-09-27 09:54:26] request.INFO: Matched route "newsfeedMessage". {"route":"newsfeedMessage","route_parameters":{"_controller":"CP\\FeedBundle\\Controller\\FeedController::newsfeedMessageAction","_route":"newsfeedMessage"},"request_uri":"https://www.website.local:8443/newsfeedMessage","method":"GET"} []
[2017-09-27 09:54:26] request.INFO: Matched route "blog_feed_item". {"route":"blog_feed_item","route_parameters":{"_controller":"CP\\FeedBundle\\Controller\\FeedController::blogFeedItemAction","_route":"blog_feed_item"},"request_uri":"https://www.website.local:8443/blog-feed-item","method":"GET"} []
...
and so on ...
...
my config.yml is setup like this:
monolog:
channels: [error]
handlers:
syslog:
type: rotating_file
level: ERROR
bubble: false
buffer_size: 1024
handler: file_log
max_files: 14
mute:
type: "null"
channels: ['snc_redis', 'doctrine', 'security']
main:
type: rotating_file
action_level: error
handler: grouped
grouped:
type: group
members: [streamed, deduplicated]
streamed:
type: rotating_file
action_level: error
bubble: false
buffer_size: 1024
max_files: 10
deduplicated:
type: deduplication
handler: swift
swift:
type: swift_mailer
from_email: "%mandrill.settings.from_email%"
to_email: "%monolog_emails%"
subject: "Website - An error have occurred!"
level: error
formatter: monolog.formatter.html
content_type: text/html
my config_prod.yml looks like this:
imports:
- { resource: config.yml }
So i expect that this info are not registered in the logs file.
What is happening and how can I avoid this being added to the logs?
I use Symfony 2.4 with monolog and have monolog configuration:
monolog:
channels: ["voter", "worker"]
handlers:
# 'critical' means HTTP 5XX responses.
critical:
type: fingers_crossed
action_level: critical
handler: critical_group
# 'error' means HTTP 4XX responses.
error:
type: fingers_crossed
action_level: error
handler: error_stream
debug:
type: fingers_crossed
action_level: debug
handler: debug_stream
critical_group:
type: group
members: critical_stream
critical_stream:
type: stream
path: %kernel.logs_dir%/%kernel.environment%_critical.log
level: critical
error_stream:
type: stream
path: %kernel.logs_dir%/%kernel.environment%_error.log
level: error
debug_stream:
type: stream
path: %kernel.logs_dir%/%kernel.environment%_warning.log
level: debug
I want to exclude warning messages from debug messages. And warning and debug messages from error messages for cleaner logs. Is any solution for this?
Thanks for any suggestions!
You can use the filter handler.
Here an additional handler based on your config:
handlers:
cleaned_debug:
type: filter
handler: debug
accepted_levels: [DEBUG]