Thanks to visit codestin.com
Credit goes to github.com

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

Conversation

simshaun
Copy link
Contributor

@simshaun simshaun commented Jul 28, 2017

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

fabpot added a commit to symfony/symfony that referenced this pull request Apr 4, 2018
… for ignoring specific HTTP codes (simshaun, fabpot)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Monolog Bridge][DX] Add a Monolog activation strategy for ignoring specific HTTP codes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9712
| License       | MIT
| Doc PR        | symfony/symfony-docs#8235

This PR introduces a Monolog activation strategy that makes it easy to ignore specific HTTP codes. e.g. Stopping logs from being flooded with 403s, 404s, and 405s.

Relevant Symfony integration PR on symfony/monolog-bundle: symfony/monolog-bundle#221

Commits
-------

6fc1cc3 added some validation
c11a8eb Add a Monolog activation strategy for ignoring specific HTTP codes
@weaverryan
Copy link
Member

Hey @simshaun! Thanks for the awesome feature - this was totally missing!

To the docs! We already have an article about excluding 404’s. I think we should actually remove that article and put your new content into a new section in the main logging.rst article (you can just do the second part - we can discuss deleting that 404 article later).

Also, have you considered adding this to the monolog recipe? We use exclude_404’s there currently. But I think this should completely replace that.

Cheers!

@weaverryan weaverryan modified the milestones: 3.4, 4.1 Apr 8, 2018
@weaverryan weaverryan removed the Waiting Code Merge Docs for features pending to be merged label Apr 8, 2018
type: fingers_crossed
handler: ...
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.

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.

@weaverryan
Copy link
Member

Also, can you switch your branch to be against master?

====================================================================

Sometimes your logs become flooded with unwanted HTTP errors, for example,
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


.. 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!

type: fingers_crossed
handler: ...
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.

I'm not sure about this suggestion because I like how compact this looks ... but I don't have a strong opinion about this.

@simshaun simshaun force-pushed the 2.7-monolog-exclude-http-codes branch from 3db3ef3 to e19bca2 Compare April 17, 2018 17:54
@simshaun simshaun changed the base branch from 2.7 to master April 17, 2018 17:54
@simshaun
Copy link
Contributor Author

I've rebased against master & added a couple comments above.

@simshaun
Copy link
Contributor Author

@weaverryan

To the docs! We already have an article about excluding 404’s. I think we should actually remove that article and put your new content into a new section in the main logging.rst article (you can just do the second part - we can discuss deleting that 404 article later).

I think the current file, monolog_regex_based_excludes.rst, could just be updated since the filename is still relevant to this feature, no?

Also, have you considered adding this to the monolog recipe? We use exclude_404’s there currently. But I think this should completely replace that.

I hadn't. That would be https://github.com/symfony/recipes/blob/master/symfony/monolog-bundle/3.1/config/packages/prod/monolog.yaml right?

javiereguiluz added a commit that referenced this pull request Apr 27, 2018
This PR was squashed before being merged into the 4.0 branch (closes #9621).

Discussion
----------

Fixed the paths of the Monolog config files

After reading this comment: #8235 (comment)  I realized that some config paths are wrong for Monolog because the recipe (https://github.com/symfony/recipes/tree/master/symfony/monolog-bundle/3.1/config/packages) doesn't create any config file in `config/packages/monolog.yaml` (all files are defined per environment).

Most of the examples used `config/packages/prod/monolog.yaml`, so I used that too. It makes sense tome because you usually only carefully configure logs in `prod`. The only article where we maintain `config/packages/dev/monolog.yaml` would be `logging/monolog_console.rst` where I think it makes sense.

Commits
-------

9de898a Fixed the paths of the Monolog config files
@weaverryan
Copy link
Member

I hadn't. That would be https://github.com/symfony/recipes/blob/master/symfony/monolog-bundle/3.1/config/packages/prod/monolog.yaml right?

Hmm, actually, your new feature in MonologBundle hasn't been released yet on MonologBundle. So, we need to wait for that. But then, it will probably be version 3.3 of MonologBundle. So, we would actually need to duplicate/create a new 3.3 directory from the 3.1 directory, with the new config. But that's ok (the duplication), that's just how the recipe system works.

I think the current file, monolog_regex_based_excludes.rst, could just be updated since the filename is still relevant to this feature, no?

Fine by me :). Let's completely replace that document with your new documentation :)

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.

@xabbuh xabbuh changed the base branch from master to 4.1 May 8, 2018 08:46
@javiereguiluz
Copy link
Member

Shaun, thanks for contributing the docs for this new feature! We're sorry it took us so long to merge it.

@javiereguiluz javiereguiluz merged commit 30cc7d4 into symfony:4.1 May 15, 2018
javiereguiluz added a commit that referenced this pull request May 15, 2018
…n, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants