Problem/Motivation

See #1289536-288: Switch Watchdog to a PSR-3 logging framework to #290 and https://github.com/php-fig/log/issues/8

Proposed resolution

Keep the current behavior, aka stick with RFC 5424 decimal levels.

For this to happen though, we should fork Psr\Log\LogLevel into Drupal\Core\Logger\RfcLogLevel and Psr\Log\LoggerTrait into Drupal\Core\Logger\RfcLoggerTrait and make our loggers (dblog and syslog) use those.
LoggerChannel should still use the PS3 LoggerTrait though and translate those values in its log() method, so that we are still compatible with any class that wants to log using PSR3 constants

Remaining tasks

Write the patch

User interface changes

None

API changes

WATCHDOG_* constants and watchdog_severity_levels() are removed

Comments

ParisLiakos’s picture

Issue summary: View changes
ParisLiakos’s picture

Issue summary: View changes
ParisLiakos’s picture

Issue summary: View changes
ParisLiakos’s picture

Issue summary: View changes
Crell’s picture

Since the values behind the constants are transparent to module developers, I don't see why we would continue to use or own rather than the standard's. We're calling our logger PSR-3, modules should use PSR-3's interface in the type hint... why add this asterisk to that?

catch’s picture

We do not have 'our own' values, we have values consistent with RFC 3164.

PSR-3 does not require using the constant values from the interface - those are just there as examples. Implementors of PSR-3 are free to use whichever constant values they like.

https://github.com/php-fig/log/issues/8 and https://github.com/php-fig/log/pull/11 both attempted to bring PSR-3 into line with common standards, but were rejected. However it's clear from those that the constant values are not considered part of PSR-3 anyway.

Additionally they aren't transparent to module developers, if you implement a logger for syslog etc., then you'd have to convert from the arbitrary strings to the decimal values anyway.

catch’s picture

sun’s picture

Created a PR for php-fig/log: https://github.com/php-fig/log/pull/21

My impression is that there is a good level of support for doing that change (which is reasonable, because the vast majority of projects are using the IETF RFC 5424 integer severity levels), but I yet have to figure out the FIG process. Last comment on the PR was to create a separate thread on the mailing list.

ParisLiakos’s picture

Status: Postponed » Active

sun opened https://groups.google.com/forum/#!topic/php-fig/Rc5YDhNdGz4
but dunno whether we actually want to a) wait for that or b) go on here with the proposed solution, and if the change is accepted we merge it later?
i would say lets go with b)

ParisLiakos’s picture

Status: Active » Postponed
ParisLiakos’s picture

Status: Postponed » Active
ParisLiakos’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new13.67 KB

Here is a patch, which also deprecated WATCHDOG_* constants and watchdog_severity_levels()
I am not sure if there is any value keeping watchdog_severity_levels() till Drupal 9.0, but well thats not up to me to decide

Status: Needs review » Needs work

The last submitted patch, 12: drupal-2267545.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review
StatusFileSize
new450 bytes
new13.96 KB

uhm, forgot use statement

catch’s picture

Thank for reviving this one! Forgot we still had this mess...

+++ b/core/lib/Drupal/Core/Logger/RfcLogLevel.php
@@ -0,0 +1,94 @@
+      static::EMERGENCY => t('Emergency'),

Don't think this should use t() - does it have to be a static method on this class or could it move elsewhere?

I'd be fine with converting the remaining uses of the WATCHDOG_* constants and removing them in this patch. They are only used internally at this point so I don't consider them part of the module-facing API. (Short section on this in #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?).

ParisLiakos’s picture

thanks for the feedback!
I was suprised to only see the WATCHDOG_* constants being used in so few places..So..i went ahead and removed them (but i doubt drush will like it)

does it have to be a static method on this class or could it move elsewhere?

Well the only other place that could make sense is introducing a logger.log_levels service, moving this there, and also splitting the mapping logic from LoggerChannel there.
Is it worth doing?

ParisLiakos’s picture

StatusFileSize
new13.61 KB
new23.73 KB

hmm, the actual files!

catch’s picture

Well the only other place that could make sense is introducing a logger.log_levels service, moving this there, and also splitting the mapping logic from LoggerChannel there.
Is it worth doing?

Not sure that's worth doing, or could be a follow-up - it's not the important thing being fixed here.

Could we use TranslationWrapper or Drupal::translation()->translate() though so the dependency is more explicit?

ParisLiakos’s picture

StatusFileSize
new1.73 KB
new24.18 KB

Drupal::translation()->translate() cant be used because strings wont be picked up by the extractor.
But TranslationWrapper is fine

catch’s picture

  1. +++ b/core/includes/common.inc
    @@ -3360,19 +3361,11 @@ function element_set_attributes(array &$element, array $map) {
     function watchdog_severity_levels() {
    

    Can also drop this as dead code I think.

  2. +++ b/core/lib/Drupal/Core/Logger/RfcLoggerTrait.php
    @@ -0,0 +1,83 @@
    + * \Psr\Log\LoggerTrait. Callers of those implementations are responsible of
    

    responsible for

Otherwise looks great now.

ParisLiakos’s picture

StatusFileSize
new3.31 KB
new25.24 KB

thank you for the quick reviews!

jonhattan’s picture

@ParisLiakos please open an issue in Drush's queue once this gets committed so we can keep drush in sync. It should be easy to fix - we have watchdog constants isolated in Drupal version specific engines.

ParisLiakos’s picture

Title: Decide if we should standardize to syslog's or PSR3 log levels » Standardize to RFC 5424 log levels
Issue summary: View changes

@jonhattan: nice! drush has no problems as proved already by testbot ;)

updating title since i think thats the direction now

catch’s picture

Status: Needs review » Reviewed & tested by the community

Can't see anything else to complain about. so RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b82e28d and pushed to 8.0.x. Thanks!

https://www.drupal.org/node/2270941 needs updating now

  • alexpott committed b82e28d on 8.0.x
    Issue #2267545 by ParisLiakos: Standardize to RFC 5424 log levels.
    
ParisLiakos’s picture

Status: Fixed » Reviewed & tested by the community

thanks, i updated the change notice.

I noticed though that the patch added an empty file unwillingly :(
can we remove it?

git rm core/lib/Drupal/Core/Logger/LogLevelMapper.php

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: drupal-2267545-20.patch, failed testing.

alexpott’s picture

Status: Needs work » Fixed

Removed empty file - a9f0c06 and pushed to 8.0.x. Thanks!

  • alexpott committed a9f0c06 on 8.0.x
    Issue #2267545 followup: Standardize to RFC 5424 log levels.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.