April 17, 2018 Javier Eguiluz

Logging as much information as possible is essential to help you debug the issues found in your applications. However, logging too much information can be as bad as logging too little, because of all the "noise" added to your logs.

That's why in Symfony 4.1 we've improved the Monolog integration to allow you exclude log messages related to specific HTTP codes. For example, when using a fingers_crossed handler, use the following configuration to ignore the logs about 403 and 404 errors:

1 2 3 4 5 6 7 # config/packages/monolog.yaml monolog : handlers : main : # ... type : 'fingers_crossed' excluded_http_codes : [ 403 , 404 ]

For more complex needs, it's also possible to exclude logs only for certain URLs, defined as regular expression patterns:

1 2 3 4 5 6 # config/packages/monolog.yaml monolog : handlers : main : # ... excluded_http_codes : [{ 400 : [ '^/foo' , '^/bar' ] }, 403 , 404 ]

If you prefer XML configuration, this is how the previous example would look like: