Skip to content

Commit 64bd394

Browse files
xabbuhweaverryan
authored andcommitted
documentation for the regex based exclusion of 404 errors with MonologBundle
(cherry picked from commit aea6533)
1 parent 5050dcf commit 64bd394

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

cookbook/logging/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Logging
66

77
monolog
88
monolog_email
9-
channels_handlers
9+
monolog_regex_based_excludes
10+
channels_handlers
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797

9898
* :doc:`/cookbook/logging/monolog`
9999
* :doc:`/cookbook/logging/monolog_email`
100+
* :doc:`/cookbook/logging/monolog_regex_based_excludes`
100101
* :doc:`/cookbook/logging/channels_handlers`
101102

102103
* :doc:`/cookbook/profiler/index`

0 commit comments

Comments
 (0)