-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Allow using #[WithLogLevel]
for setting custom log level for exceptions
#48747
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
Conversation
#[LogLevel]
for setting custom log level for exceptions#[LogLevel]
for setting custom log level for exceptions
9be54ba
to
fc8c107
Compare
src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php
Outdated
Show resolved
Hide resolved
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.
Thanks. Don't miss adding a changelog entry.
#[LogLevel]
for setting custom log level for exceptions#[LogLevel]
for setting custom log level for exceptions
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.
Thank you for working on this. Looks like a nice feature.
src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php
Outdated
Show resolved
Hide resolved
4d35720
to
e24c5ba
Compare
final class LogLevel | ||
{ | ||
/** | ||
* @param \Psr\Log\LogLevel::* $level |
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.
Can we use a use
statement here to simplify the code?
* @param \Psr\Log\LogLevel::* $level | |
* @param LogLevel::* $level |
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.
We cannot simplify it to just LogLevel
because the attribute class has the same name, so we'll have to add an alias, thus I don't see any benefit from adding the use
statement.
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.
This naming conflict is indeed unfortunate because the one thing you want to pass to the constructor of the LogLevel
attribute is a LogLevel
constant. This makes the everyday use of the attribute a bit cumbersome. Maybe we should rename the attribute?
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 open to suggestions as I couldn't think of a better name for the attribute.
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.
Dunno… AsLogLevel
, WithLogLevel
, AssignLogLevel
, … 🤷🏻♂️
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.
MapLogLevel?
We already have a few Map* attributes
Worth renaming HttpStatus to MapHttpStatus?
Another idea could be At*
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.
Not sure about Map
as it's used for argument mapping/binding/resolution AFAIK, and At
feels weird for the status code. Another proposal: #[ToLogLevel]
& #[ToHttpStatus]
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 renamed the class to WithLogLevel
as it makes most sense to me. I can change it to something else if needed. I will also submit a PR to update the HttpStatus
attribute accordingly after this is merged.
068b899
to
33c3a7c
Compare
#[LogLevel]
for setting custom log level for exceptions#[WithLogLevel]
for setting custom log level for exceptions
src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php
Outdated
Show resolved
Hide resolved
…el for exceptions
d9bfaea
to
0a2563d
Compare
Thank you @angelov. |
As a follow-up, I've created #48876 to rename HttpStatus to WithHttpStatus. |
…tus (fabpot) This PR was merged into the 6.3 branch. Discussion ---------- [HttpKernel] Rename HttpStatus atribute to WithHttpStatus | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes-ish | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Refs #48352 and #48747 As discussed in the 2 referenced PRs for better naming consistency. Commits ------- fece766 [HttpKernel] Rename HttpStatus atribute to WithHttpStatus
With these changes, we're extending the functionality for setting a custom log level for a given exception by introducing a new
WithLogLevel
attribute.Example:
This will have a lower priority compared to the log level set using the option in the configuration files.
(Meaning that if we have both an attribute declared on an exception class, and another level set for the same class in the configuration, the one from the configuration will be used.)