New in Symfony 4.1: Ignore specific HTTP codes from logs
April 17, 2018 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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>
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
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.
No difference.