Problem/Motivation

Drupal has a map of PSR3 log level constants to RFC 5424 log level constants, but hides it in a protected variable. This map should arguably be available as a constant.

Steps to reproduce

Proposed resolution

Deprecate the Drupal\Core\Logger\LoggerChannel::$levelTranslation protected variable in favor of a new constant Drupal\Core\Logger\LoggerChannel::LEVEL_TRANSLATION (or Drupal\Core\Logger\LoggerChannel::LEVEL_MAP)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#9 3432889-nr-bot.txt3.86 KBneeds-review-queue-bot

Issue fork drupal-3432889

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mfb created an issue. See original summary.

mfb’s picture

Title: Make the map of PSR3 log constants to RFC 5424 log constants available as a constant » Make the map of PSR3 to RFC 5424 log level constants available as a constant
Issue summary: View changes
Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change to a constant makes sense.

mstrelan’s picture

Status: Reviewed & tested by the community » Needs review

Wonder if we'd be better off making RfcLogLevel in to an enum and move the mapping to a function there. Setting NR for the idea, please set to NW if you agree or back to RTBC if not.

mfb’s picture

@mstrelan I think you're suggesting an API change, if the RfcLogLevels would be objects rather than simple constants? That doesn't seem worth the developer friction to do.

Ok, I guess you could have an enum that also has the original constants pointing to the enum values, and there would be no API change, but then, what's the point?

Note also that Drupal\Core\Logger\RfcLogLevel is basically drupal's (moar RFC-compliant) version of Psr\Log\LogLevel, so it seems reasonable for them to have the same architecture.

mstrelan’s picture

This is what I had in mind, happy to be told it's not worth it, just thought it was worth considering.

https://git.drupalcode.org/project/drupal/-/merge_requests/7178

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new3.86 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mfb’s picture

@mstrelan: Seems not worth it for the reasons I said in #6 but, if you want to discuss you could open a new issue? It seems only tangentially related to this issue, which was just to make the level map available, not to change any public APIs.

mfb’s picture

Well, in the contrib module that this would've been useful for, I ended up introducing my own LogLevel enum to manage all the log level logic :)

So, I don't really need this anymore; feel free to close this issue as far as I'm concerned (or, perhaps the original feature request could still be useful for other developers).

quietone’s picture

This looks familiar. Searching found an earlier issue for this which I closed as a duplicate.

mfb’s picture

@quietone I actually suggested closing this issue, as it was pretty trivial to copy the map into two contrib modules where this feature could've been useful. Btw, I don't see how that other issue is a duplicate?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.