How to Configure Monolog to Exclude Specific HTTP Codes from the Log

Version: 4.2
Edit this page

Warning: You are browsing the documentation for Symfony 4.2, which is no longer maintained.

Read the updated version of this page for Symfony 6.0 (the current stable version).

How to Configure Monolog to Exclude Specific HTTP Codes from the Log

Sometimes your logs become flooded with unwanted HTTP errors, for example, 403s and 404s. When using a fingers_crossed handler, you can exclude logging these HTTP codes based on the MonologBundle configuration:

  • YAML
  • XML
  • PHP
1
2
3
4
5
6
7
8
# config/packages/prod/monolog.yaml
monolog:
    handlers:
        main:
            # ...
            type: fingers_crossed
            handler: ...
            excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }]
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.