|
| 1 | +.. index:: |
| 2 | + single: Logging |
| 3 | + single: Logging; Exclude 404 Errors |
| 4 | + single: Monolog; Exclude 404 Errors |
| 5 | + |
| 6 | +How to Configure Monolog to Exclude 404 Errors from the Log |
| 7 | +=========================================================== |
| 8 | + |
| 9 | +Sometimes you get your logs flooded with unwanted 404 HTTP errors, for example, |
| 10 | +when an attacker scans your app for some well-known application paths (e.g. |
| 11 | +`/phpmyadmin`). When using a ``fingers_crossed`` handler, you can exclude |
| 12 | +logging these 404 errors based on a regular expression in the MonologBundle |
| 13 | +configuration: |
| 14 | + |
| 15 | +.. configuration-block:: |
| 16 | + |
| 17 | + .. code-block:: yaml |
| 18 | +
|
| 19 | + # app/config/config.yml |
| 20 | + monolog: |
| 21 | + handlers: |
| 22 | + main: |
| 23 | + # ... |
| 24 | + type: fingers_crossed |
| 25 | + handler: ... |
| 26 | + excluded_404s: |
| 27 | + - ^/phpmyadmin |
| 28 | +
|
| 29 | + .. code-block:: xml |
| 30 | +
|
| 31 | + <!-- app/config/config.xml --> |
| 32 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 33 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 34 | + xmlns:monolog="http://symfony.com/schema/dic/monolog" |
| 35 | + xsi:schemaLocation="http://symfony.com/schema/dic/services |
| 36 | + http://symfony.com/schema/dic/services/services-1.0.xsd |
| 37 | + http://symfony.com/schema/dic/monolog |
| 38 | + http://symfony.com/schema/dic/monolog/monolog-1.0.xsd" |
| 39 | + > |
| 40 | + <monolog:config> |
| 41 | + <monolog:handler type="fingers_crossed" name="main" handler="..."> |
| 42 | + <!-- ... --> |
| 43 | + <monolog:excluded-404>^/phpmyadmin</monolog:excluded-404> |
| 44 | + </monolog:handler> |
| 45 | + </monolog:config> |
| 46 | + </container> |
| 47 | +
|
| 48 | + .. code-block:: php |
| 49 | +
|
| 50 | + // app/config/config.php |
| 51 | + $container->loadFromExtension('monolog', array( |
| 52 | + 'handlers' => array( |
| 53 | + 'main' => array( |
| 54 | + // ... |
| 55 | + 'type' => 'fingers_crossed', |
| 56 | + 'handler' => ..., |
| 57 | + 'excluded_404s' => array( |
| 58 | + '^/phpmyadmin', |
| 59 | + ), |
| 60 | + ), |
| 61 | + ), |
| 62 | + )); |
| 63 | +
|
| 64 | +.. note:: |
| 65 | + |
| 66 | + To be able to use ``excluded_404s`` option you need to update your version |
| 67 | + of the MonologBundle to 2.4. |
0 commit comments