Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c30ff06

Browse filesBrowse files
committed
minor #8235 Document new Monolog HTTP code exclusion feature (simshaun, javiereguiluz)
This PR was merged into the 4.1 branch. Discussion ---------- Document new Monolog HTTP code exclusion feature I'm submitting PRs on symfony/symfony and symfony/monolog-bundle that introduces an easy way of excluding specific HTTP codes from Monolog. This PR documents that new feature, pending its acceptance. Pending PRs: symfony/symfony#23707 symfony/monolog-bundle#221 Commits ------- 30cc7d4 Added the versionadded directive c8c19f2 Update to Symfony 4 paths e19bca2 Fix indentation 17cb416 Update configuration format to support URL blacklist c9f6ee5 Fix title underline length a3b6a01 Document new Monolog HTTP code exclusion feature
2 parents 528857d + 30cc7d4 commit c30ff06
Copy full SHA for c30ff06

File tree

1 file changed

+65
-0
lines changed
Filter options

1 file changed

+65
-0
lines changed
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. index::
2+
single: Logging
3+
single: Logging; Exclude HTTP Codes
4+
single: Monolog; Exclude HTTP Codes
5+
6+
How to Configure Monolog to Exclude Specific HTTP Codes from the Log
7+
====================================================================
8+
9+
..versionadded:: 4.1
10+
The ability to exclude log messages based on their status codes was
11+
introduced in Symfony 4.1 and MonologBundle 3.3.
12+
13+
Sometimes your logs become flooded with unwanted HTTP errors, for example,
14+
403s and 404s. When using a ``fingers_crossed`` handler, you can exclude
15+
logging these HTTP codes based on the MonologBundle configuration:
16+
17+
.. configuration-block::
18+
19+
.. code-block:: yaml
20+
21+
# config/packages/prod/monolog.yaml
22+
monolog:
23+
handlers:
24+
main:
25+
# ...
26+
type: fingers_crossed
27+
handler: ...
28+
excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }]
29+
30+
.. code-block:: xml
31+
32+
<!-- config/packages/prod/monolog.xml -->
33+
<container xmlns="http://symfony.com/schema/dic/services"
34+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
35+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
36+
xsi:schemaLocation="http://symfony.com/schema/dic/services
37+
http://symfony.com/schema/dic/services/services-1.0.xsd
38+
http://symfony.com/schema/dic/monolog
39+
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
40+
41+
<monolog:config>
42+
<monolog:handler type="fingers_crossed" name="main" handler="...">
43+
<!-- ... -->
44+
<monolog:excluded-http-code code="403">
45+
<monolog:url>^/foo</monolog:url>
46+
<monolog:url>^/bar</monolog:url>
47+
</monolog:excluded-http-code>
48+
<monolog:excluded-http-code code="404" />
49+
</monolog:handler>
50+
</monolog:config>
51+
</container>
52+
53+
.. code-block:: php
54+
55+
// config/packages/prod/monolog.php
56+
$container->loadFromExtension('monolog', array(
57+
'handlers' => array(
58+
'main' => array(
59+
// ...
60+
'type' => 'fingers_crossed',
61+
'handler' => ...,
62+
'excluded_http_codes' => array(403, 404),
63+
),
64+
),
65+
));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.