Problem/Motivation

Code changes like these (API change from #1289536: Switch Watchdog to a PSR-3 logging framework) make it impossible to extract log categories/channels, so attempting to translate them is pointless:

BEFORE:

watchdog('blabla', 'Message');

AFTER:

$logger = $container->get('logger.factory')->get('blabla');
$logger->notice('Message');

Extraction of the string 'blabla' here is getting ridiculously hit and miss. There are bazillions of ways you may get that logger and the get() method is impossible to target with a code parser. With complex code structures like that, it seems totally pointless to even try to translate the message category at this point. That's what you get for nice and dynamic code structures.

Proposed resolution

There are 2 choices:

  1. keep translating log category/channel names like we did for 9 years (although time is not necessarily an indication of good practice :), then we need to rename get() on the logger channel interface to something more concrete like getChannel(), see #21
  2. stop translating log category/channel names, see #3

Remaining tasks

Discuss. Review. Commit.

User interface changes

If option 1 is chosen, type like 'dblog', 'comment', 'node', etc. will never be translated on the UI (both shown as a column in dblog's view and in a select box to filter).

API changes

If option 2 is chosen the log channel API is changed to use getChannel() instead

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

Issue summary: View changes
webchick’s picture

Could we handle this with a specific wrapper function like Logger::get() and use that everywhere instead of magic, undocumentable methods?

Gábor Hojtsy’s picture

Should change the place where we build the select box options.

Gábor Hojtsy’s picture

@webchick: because of injection: the way eg. #2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form uses the log API it injects it via the container. With the API set so loose, there is really no way of limiting them not to inject the logger in some way, store it on a property like it is done there, etc.

One way to make it extractable regardless of injection is to rename get() to getLoggerChannel() or something very specific so we can target it in an extractor. Maybe I jumped the gun too soon here and should have suggested a nice rename like that :D I did assume the channel concept is part of the PSR-3 logger, but it does not seem to be reading https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logg... -- it looks like we added that on top. If we are to rename it, we'll need to document the hell out of it, or people will want to rename it to get() because of DX.

sun’s picture

Translating these internal log message channel/type identifiers, or even treating them as human-readable string labels, never made sense to me in the first place.

They are not properly capitalized, they are as short as technically possible/sensible, and they make no sense without context.

The channel names should be internal identifiers like "routing", "authentication", etc.pp. — They may be mapped to human-readable labels for UI purposes, but that would and should be a separate process, so that e.g. "auth" or "authentication" turns into "Authentication".

andypost’s picture

Makes sense! Also let's remove broken examples

Gábor Hojtsy’s picture

@sun: if that is a universally accepted position (no problem, I agree these strings are at a minimum at the border of pointless being translated either way), we should probably not have the comment I added. The comment makes sense if we think they should ideally be translated but we don't want to make the DX of loggers worse just so translated sites get translated log categories (although they got it in several prior major core versions).

@andypost: this issue is not about translating (or not) of the messages themselves, but the 'channel' string that comes before that on the lines you modified.

ParisLiakos’s picture

i am fine with renaming get() to getLogger().
But i also agree with sun. i dont really see a point translating channel names

andypost’s picture

Gábor Hojtsy’s picture

BTW as for the messages themselves, the new logger API introduced 9 new ways to define translatable strings, see #2285063: Support for Drupal 8 logger API. (Tenth would be the category/channel).

sun’s picture

I'm not sure whether we ever really laid out a proper plan for log channels.

Given that watchdog/logging was and still is our only construct for global/application-wide notifications for site administrators, and given that the UI implementation of dblog is enabled by default, we collectively developed a habit of (ab)using log message channel/type names as a way to categorize "notifications" on an additional axis that is normally not supposed to exist in a well-formed logging architecture.

The prime example for that are the "not found" and "access denied" log channel/type names. They belong to respective "routing" and "access" channels under any normal circumstances. Each of these channels ought to contain other messages other than 404 or 403 messages. Each message has a severity, but that's it. Using a custom/different channel name for each possible log message defeats the whole purpose of log channels. E.g., an "access" channel should focus on and reveal access internals only, possibly even giving hints on why exactly access was granted or denied.

The lack of a clear and proper design causes contrib to invent really stupid own channel names (or to not perform any logging at all).

In short, I think there's much more for us to figure out and fix in this architectural space. A registry of available channels may or may not help. Based on that, it would be easier to evaluate whether mapping/translating channel names makes any sense or not.

Gábor Hojtsy’s picture

The Drupal 8 API still promotes per module / component names for channels, so you may get access denied messages from channels like 'comment' and 'og'.

As for translating the type name, we started translating watchdog() type names in 4.4.0 for menu items and in the filter form and the table display in 4.6.0. (So this is a practice we did for the last 9 years at least). Its fine to say this is not something we want to continue doing IMHO, if we decide with the consequences in mind.

larowlan’s picture

I'll ping grom358 to see if pharborist can help here

Gábor Hojtsy’s picture

Title: Log message type translation is now pointless / impossible » Decide if we still want to translate log channel names and make modifications accordingly
Issue summary: View changes

@larowlan: I don't know what kind of high level help would be needed here. I think there are 2 choices:

- keep translating log category/channel names like we did for 9 years (although time is not necessarily an indication of good practice :), then we need to rename get() on the logger channel interface to something more concrete like getChannel(), patch for that attached, although will probably fail at places
- stop translating log category/channel names (see prior patches on this issue)

Retitled for more options and updated issue summary.

Gábor Hojtsy’s picture

FileSize
1.71 KB

Status: Needs review » Needs work

The last submitted patch, 15: getchannel.patch, failed testing.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
521 bytes
2.22 KB

Status: Needs review » Needs work

The last submitted patch, 17: getchannel-17.patch, failed testing.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
469 bytes
2.68 KB

Things that not even phpstorm's magic refactoring can resolve :P

Status: Needs review » Needs work

The last submitted patch, 19: getchannel-19.patch, failed testing.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
1.6 KB
4.27 KB

And the remaining ones I found & the tests found.

Gábor Hojtsy’s picture

Issue summary: View changes
Gábor Hojtsy’s picture

Now two complete patches for the two approaches #21 and #3. One of them is the solution to this issue. Feedback please.

andypost’s picture

Views does not translate type, suppose it's good to combine patches

Gábor Hojtsy’s picture

@andypost: solution to that depends on what we decide here. Any feedback on the patches / which way to go?

andypost’s picture

@Gabor, I see #3 as solution - no reason to translate channel name!
I can't get how renaming of the method affects "translatability" of channel? separate issue?

Gábor Hojtsy’s picture

@andypost: maybe read the issue summary? Let me rephrase it for you. The channel getter method is the only place which has the channel name. $logger_factory->get('comment');. This is impossible to target with string extraction therefore the source string will never be able to appear as a source translatable string (at least until the code is run). IF we want to keep it translated, the only way to make the extraction work is to give the method a more specific name, so extraction can target it. The issue summary has both options laid out.

jhedstrom’s picture

Status: Needs review » Needs work

Patch above no longer applies and will need a reroll if this is still being considered.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Status: Needs work » Closed (works as designed)

Discussed this with Gábor and agreed leaving these untranslatable is fine.