8000 Document new Monolog HTTP code exclusion feature by simshaun · Pull Request #8235 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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
merged 6 commits into from
May 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Document new Monolog HTTP code exclusion feature
  • Loading branch information
simshaun committed Apr 17, 2018
commit a3b6a01c4b70002fdfe535b4090cdf2153fa6857
60 changes: 60 additions & 0 deletions logging/monolog_exclude_http_codes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. 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
===========================================================

Sometimes your logs become flooded with unwanted HTTP errors, for example,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a versionadded here:

..versionadded:: 4.1
    The ability to exclude status codes was introduced in Symfony 4.1 and MonologBundle 3.3.

I'm guessing on the 3.3 part for MonologBundle, but unless something super strange happens, that should be true.

403s and 404s. When using a ``fingers_crossed`` handler, you can exclude
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: is the mention of the fingers_crossed handler just an example or does this feature only work with that specific handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based the feature off of NotFoundActivationStrategy, which is only for fingers_crossed

logging these HTTP codes based on the MonologBundle configuration:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the file paths for Symfony 4: app/config/config.* -> config/packages/monolog.* Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually haven't gotten to mess with Symfony 4 much yet, but I just installed symfony/website-skeleton to look. It looks like it has:

  • config/packages/dev/monolog.yml
  • config/packages/prod/monolog.yml
  • config/packages/test/monolog.yml

I don't see one just in config/packages/. Should I just update the comment to something like:

# config/packages/{{env}}/monolog.yml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Let's add prod environment in the example because most of the times you only care about configuring logs in prod (and we use prod in most of the examples in the docs). Also, beware that in Symfony 4 the file extension is .yaml instead of .yml Thanks!

monolog:
handlers:
main:
# ...
type: fingers_crossed
handler: ...
excluded_http_codes:
- 403
- 404

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:

excluded_http_codes: [
    403, 
    404, 
    { 400: ['^/foo', '^/bar'] }
]

or B:

excluded_http_codes: 
    - 403
    - 404
    - 
        400: 
            - ^/foo
            - ^/bar

Copy link
Member

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.

.. code-block:: xml

<!-- app/config/config.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>403</monolog:excluded-http-code>
<monolog:excluded-http-code>404</monolog:excluded-http-code>
</monolog:handler>
</monolog:config>
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('monolog', array(
'handlers' => array(
'main' => array(
// ...
'type' => 'fingers_crossed',
'handler' => ...,
'excluded_http_codes' => array(403, 404),
),
),
));
0