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:
1 2 3 4 5 6 7 8 9 10 11 12
<!-- config/packages/monolog.xml -->
<monolog:config>
<monolog:handler type="fingers_crossed" name="main" handler="...">
<!-- ... -->
<monolog:excluded-http-code code="400">
<monolog:url>^/foo</monolog:url>
<monolog:url>^/bar</monolog:url>
</monolog:excluded-http-code>
<monolog:excluded-http-code code="403" />
<monolog:excluded-http-code code="404" />
</monolog:handler>
</monolog:config>
Super feature. Thanks.
Thanks for that feature!
[REDACTED], ça nous serait utile mais on est encore en 3.4 ☹️
Is it possible to backport this feature to the 3.x series?
🙌
new features are NEVER backported into a maintenance branch (and we won't be doing any new minor release of 3.x)
Looks interesting. Thanks! Is there any difference between "excluded_404s" with "- ^/" and "excluded_http_codes" with "[404]". The second one seems to be more flexible and allow skip not only 404.
@Dominik Hajduk
No difference.
@Shaun Simmons thanks!