Skip to content
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

[HttpKernel][DX] Allow the log level of http exceptions to be overridden #25533

Closed
wants to merge 13 commits into from

Conversation

mtibben
Copy link
Contributor

@mtibben mtibben commented Dec 17, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #9712
License MIT
Doc PR

This allows the log level to be configured based on the specific HTTP status code.

This is an alternative approach to #23707. The problem with the approach in #23707 (and with the documented approaches to filter 404s) is that it only works with the fingers crossed handler. However the fingers crossed handler introduces unwanted behaviour, adds complexity to the log configuration, and can be confusing for a developer.

This PR takes a more direct approach. The actual problem is that different applications have different requirements as to what level a specific http code should be logged at. So this makes this behaviour directly configurable.

@carsonbot carsonbot added Status: Needs Review HttpKernel DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature labels Dec 17, 2017
@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Dec 18, 2017
@mtibben mtibben force-pushed the master branch 3 times, most recently from 59d8bb4 to f361cec Compare December 19, 2017 09:37
Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

i think i'd be in favor or 4xx logged as WARNING, that would save us some regular log filtering :-)

for the framework config; should it be semantic? framework.http_exception.log_levels or so?

@mtibben
Copy link
Contributor Author

mtibben commented Dec 27, 2017

i think i'd be in favor or 4xx logged as WARNING, that would save us some regular log filtering :-)

Done - how does this impact BC?

for the framework config; should it be semantic? framework.http_exception.log_levels or so?

Yes that makes a lot more sense.

@mtibben mtibben force-pushed the master branch 2 times, most recently from e67cb94 to 3a8f92f Compare December 27, 2017 07:31
@mtibben
Copy link
Contributor Author

mtibben commented Dec 27, 2017

for the framework config; should it be semantic? framework.http_exception.log_levels or so?

I've just implemented the configuration changes, for example it currently looks something like

twig:
    http_exception_log_levels:
        404: INFO
        403: NOTICE

I'll need some guidance on how to make this configurable via the framework bundle rather than the twig bundle @ro0NL.

Actually it seems pretty weird to me that the twig bundle is responsible for logging http exceptions... any reason behind that, or just an accident of history?

@mtibben mtibben force-pushed the master branch 4 times, most recently from 10de391 to ed7c409 Compare December 27, 2017 10:28
@ro0NL
Copy link
Contributor

ro0NL commented Dec 27, 2017

Actually it seems pretty weird to me that the twig bundle is responsible for logging http exceptions... any reason behind that, or just an accident of history?

Agree, and it's the way it's always has been AFAIK. Note recently we decoupled logging from rendering into different priorities (see #25366), perhaps now we should favor 2 different listeners instead (logging in the framework bundle, rendering in the twig bundle).

cc @fabpot

@mtibben
Copy link
Contributor Author

mtibben commented Jan 4, 2018

perhaps now we should favor 2 different listeners instead (logging in the framework bundle, rendering in the twig bundle)

Looking at this, but might be tricky to do in a BC way

@mtibben mtibben force-pushed the master branch 2 times, most recently from 87ac731 to 89c2dee Compare January 5, 2018 04:02
@mtibben
Copy link
Contributor Author

mtibben commented Jan 5, 2018

I've had an initial stab at splitting the listener into two.

  • LoggingExceptionListener - Logging
  • RenderControllerExceptionListener - Rendering an error controller

I've left the original ExceptionListener in place for BC, although it's no longer used by the framework. Any suggested strategy to deal with BC for old services?

And what's the BC policy for service names? Is it OK to remove old service names?

@mtibben
Copy link
Contributor Author

mtibben commented Jan 5, 2018

And the config looks like

framework:
    http_exception_log_levels:
        404: INFO
        403: NOTICE

@mtibben mtibben force-pushed the master branch 7 times, most recently from 9b9ee9e to a7c5bdf Compare January 9, 2018 21:29
@mtibben
Copy link
Contributor Author

mtibben commented Jan 9, 2018

OK this is ready for further feedback @ro0NL @nicolas-grekas @sstok. I'm not sure why the tests on php 7.2 are failing though 😕

@mtibben
Copy link
Contributor Author

mtibben commented Jan 19, 2018

I've rebased on the latest master, any feedback?

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@fabpot
Copy link
Member

fabpot commented Sep 8, 2019

@yceruto Maybe you can help here.

@fabpot fabpot closed this Oct 7, 2020
@fabpot
Copy link
Member

fabpot commented Oct 7, 2020

We've just moved away from master as the main branch to use 5.x instead. Unfortunately, I cannot reopen the PR and change the target branch to 5.x. Can you open a new PR referencing this one to not loose the discussion? Thank you for your understanding and for your help.

@mtibben
Copy link
Contributor Author

mtibben commented Oct 7, 2020

I won't get a chance to revisit this. If anyone else reading this wants to pick this up, feel free!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature for 5.x HttpKernel Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants