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?
Related
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]
Welcome,
My task is to change the convention of loggers in the application. Currently, loggers are configured as dedicated services. I would like to define the loggers in the Symfony convention and ensure backward compatibility by defining DI directing the old names of logger services to the new ones in the monolog.logger.channel convention. I have the loggers in Symfony do things for the first time or can anyone give me an example of how to do it? Thank you in advance and I greet you below with my current configuration:
app/config/config_dev.yml:
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ['!my_channel']
my_handler:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.my_handler.log"
level: debug
channels: ['my_channel']
console:
type: console
bubble: false
app/config/config_prod.yml:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
channels: ['!my_channel']
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
my_channel:
type: fingers_crossed
action_level: error
handler: my_channel_stream
my_channel_stream:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.my_channel.log"
level: debug
channels: ['my_channel']
src/bundle/Resources/config/logger.yml:
services:
logger:
class: Symfony\Bridge\Monolog\Logger
arguments: [logger]
calls:
- [pushHandler, ['#monolog.handler.console']]
- [pushHandler, ['#logger_handler']]
logger_handler:
class: Monolog\Handler\StreamHandler
arguments: ["%kernel.logs_dir%/%kernel.environment%.cof.log", 200]
src/bundle/Resources/config/config.yml:
monolog:
channels: ['my_channel']
I am using Monolog in a Symfony2 and now it's configured in this way:
services:
monolog.formatter.html:
class: Monolog\Formatter\HtmlFormatter
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: swift
handler: grouped
grouped:
type: group
members: [streamed, buffered]
streamed:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
buffered:
type: buffer
handler: swift
swift:
type: swift_mailer
from_email: 'email#gmail.com'
to_email: 'email#gmail.com'
subject: An Error Occurred!
level: debug
content_type: text/html
formatter: monolog.formatter.html
And now it send me information about all events on my site. How can I configure it, to receive only messages about exceptions?
Additionly, most exceptions that i should catch and email came from guzzle library. Something like ( Client error response )
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]
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