-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document new Monolog HTTP code exclusion feature #8235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
javiereguiluz
merged 6 commits into
symfony:4.1
from
simshaun:2.7-monolog-exclude-http-codes
May 15, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a3b6a01
Document new Monolog HTTP code exclusion feature
simshaun c9f6ee5
Fix title underline length
simshaun 17cb416
Update configuration format to support URL blacklist
simshaun e19bca2
Fix indentation
simshaun c8c19f2
Update to Symfony 4 paths
simshaun 30cc7d4
Added the versionadded directive
javiereguiluz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.. index:: | ||
single: Logging | ||
single: Logging; Exclude HTTP Codes | ||
single: Monolog; Exclude HTTP Codes | ||
|
||
How to Configure Monolog to Exclude Specific HTTP Codes from the Log | ||
==================================================================== | ||
|
||
..versionadded:: 4.1 | ||
The ability to exclude log messages based on their status codes was | ||
introduced in Symfony 4.1 and MonologBundle 3.3. | ||
|
||
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: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/prod/monolog.yaml | ||
monolog: | ||
handlers: | ||
main: | ||
# ... | ||
type: fingers_crossed | ||
handler: ... | ||
excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }] | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/prod/monolog.xml --> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:monolog="http://symfony.com/schema/dic/monolog" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/monolog | ||
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"> | ||
|
||
<monolog:config> | ||
<monolog:handler type="fingers_crossed" name="main" handler="..."> | ||
<!-- ... --> | ||
<monolog:excluded-http-code code="403"> | ||
<monolog:url>^/foo</monolog:url> | ||
<monolog:url>^/bar</monolog:url> | ||
</monolog:excluded-http-code> | ||
<monolog:excluded-http-code code="404" /> | ||
</monolog:handler> | ||
</monolog:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/prod/monolog.php | ||
$container->loadFromExtension('monolog', array( | ||
'handlers' => array( | ||
'main' => array( | ||
// ... | ||
'type' => 'fingers_crossed', | ||
'handler' => ..., | ||
'excluded_http_codes' => array(403, 404), | ||
), | ||
), | ||
)); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use the multi line format - one status code per line - I think it will be more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this suggestion because I like how compact this looks ... but I don't have a strong opinion about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind either way. I think multi-line might be a little clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the preferred format for multi-line arrays in YAML?
A:
or B:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weaverryan don't you think the expanded format is less readable in this case? The empty space in the last element in the B) notation is confusing ... and the A) format is a bit confusing too because of the way the brackets are displayed.