Problem/Motivation

So, I'm not sure if this is the best way to organize things. At any rate, I've done the work to inject the logger factory. I've done a `grep -r --
Drupal::logger core` and gotten the results in the attached file.

Proposed resolution

Remaining tasks

  1. Check if there are more to do in non-test code.

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-2981326

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

vegantriathlete created an issue. See original summary.

vegantriathlete’s picture

Status: Active » Needs review
StatusFileSize
new5.91 KB

Note that it seems like the ModuleInstaller had some weirdness with the constructor not reflecting all the services that were being injected.

Status: Needs review » Needs work

The last submitted patch, 2: inject_logger_factory-2981326-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dhirendra.mishra’s picture

Issue summary: View changes
StatusFileSize
new6.13 KB

Please find below my patch.Passing $logger_factory service to construct function in #2 patch.
Please review it and test it.

vegantriathlete’s picture

@dhirendra: can you please include an interdiff so that we know what the difference is between your patch and the original one?

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new871 bytes

Added a interdiff file.

joachim’s picture

Looks ok apart from:

+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -59,14 +75,20 @@ class ModuleInstaller implements ModuleInstallerInterface {
+    $this->routeBuilder = $route_builder;

Why is the route builder being added here?

vegantriathlete’s picture

The route builder is being added because the service was already injecting the route builder before. In order to inject the logger factory service, it had to come after the route builder. I figured that as long as the route builder was being injected it might as well be used. I wonder if we could / should just skip injecting it completely. However, that seemed like too much of a change for this issue.

vegantriathlete’s picture

@dhirendra: Good catch noticing that I had forgotten to inject the logger channel factory interface.

joachim’s picture

> I figured that as long as the route builder was being injected it might as well be used. I wonder if we could / should just skip injecting it completely. However, that seemed like too much of a change for this issue.

It does seem like too much of a change. But adding DI boilerplate is increasing the work for when the parameter in services.yml is cleaned up. I would be inclined to file a blocker issue to clean that up first.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

martin107’s picture

Status: Needs review » Reviewed & tested by the community

I would be inclined to file a blocker issue to clean that up first.

I appreciate issues with a single minded focus...

Reviewers can come in grasp the concept and see that it is repeated ad nauseam.

For this issue, I find myself with the other perspective. There is goodness here that I don't want to delay.

Sure the routeBuilder refinement is out of scope ... but it is easy to see that it too is good/"going in the right direction" .. Yes we should file a follow up

But I would rather not see this issue further delayed.

I hear the drum beat of Drupal9 .. Symfony4 is removing $container->get() so injection is soon to be a thorn in the lion's paw.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: inject_logger_factory-2981326-4.patch, failed testing. View results

dhirendra.mishra’s picture

Do we need re-rolling of patch here?

dhirendra.mishra’s picture

Status: Needs work » Reviewed & tested by the community
dhirendra.mishra’s picture

Status: Reviewed & tested by the community » Needs review

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

jungle’s picture

Title: Inject logger factory instead of using \Drupal::logger » Replace non-test usages of \Drupal::logger() with IoC injection
Parent issue: » #2729597: [meta] Replace \Drupal with injected services where appropriate in core
Related issues: -#2729597: [meta] Replace \Drupal with injected services where appropriate in core
StatusFileSize
new5.77 KB
new4.86 KB

As needs reroll, adjust the title/scope a little bit.

jungle’s picture

Issue summary: View changes
+++ b/core/core.services.yml
@@ -445,6 +445,9 @@ services:
+  logger.channel.theme:

@@ -522,7 +525,7 @@ services:
+    arguments: ['%app.root%', '@module_handler', '@kernel', '@logger.channel.default']

@@ -1490,7 +1493,7 @@ services:
+    arguments: ['%app.root%', '@theme.negotiator', '@theme.initialization', '@module_handler', '@logger.channel.theme']

+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -59,14 +68,17 @@ class ModuleInstaller implements ModuleInstallerInterface {
+  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, LoggerInterface $logger) {

+++ b/core/lib/Drupal/Core/Theme/ThemeManager.php
@@ -67,12 +75,15 @@ class ThemeManager implements ThemeManagerInterface {
+  public function __construct($root, ThemeNegotiatorInterface $theme_negotiator, ThemeInitializationInterface $theme_initialization, ModuleHandlerInterface $module_handler, LoggerInterface $logger) {

Unlike #4, injected logger channels instead of the logger factory.

+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -59,14 +75,20 @@ class ModuleInstaller implements ModuleInstallerInterface {
+   * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
+   *   The route building service.
...
-  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) {
+  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel, RouteBuilderInterface $route_builder, LoggerChannelFactoryInterface $logger_factory) {

Injected/introduced route building service in #2 was removed, out of scope here.

Tasks left:

  1. Check if there are more to do in non-test code.
  2. add change record(s) and add BC layers for the __construct changes.

Applied issue summary template to IS

jungle’s picture

Issue summary: View changes
StatusFileSize
new6.46 KB
new2.92 KB

CR added. Adding BC layers.

jungle’s picture

Issue summary: View changes
StatusFileSize
new6.47 KB
new2.08 KB
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -68,16 +68,20 @@ class ModuleInstaller implements ModuleInstallerInterface {
+      @trigger_error('The logger.channel.default service must be passed to ' . __CLASS__ . '::'. __METHOD__ . '(). It was added in drupal:9.1.0 and will be required before drupal:10.0.0. See https://www.drupal.org/node/3160464', E_USER_DEPRECATED);

No space betwtten '::'and ., addressing.

Status: Needs review » Needs work

The last submitted patch, 23: 2981326-23.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new6.47 KB
new3.36 KB

Last patch failed to apply , re-rolling the patch and rearranging use statement alphabetically order. Kindly review a new patch.

Status: Needs review » Needs work

The last submitted patch, 25: 2981326-25.patch, failed testing. View results

jungle’s picture

Status: Needs work » Needs review

Can't fix the tests failed, so instead of inject logger channels, back to inject logger factory.

jungle’s picture

StatusFileSize
new6.57 KB
new6.07 KB

Forgot uploading the patch.

Status: Needs review » Needs work

The last submitted patch, 28: 2981326-27.patch, failed testing. View results

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

borisson_’s picture

This needs a reroll because it no longer applies currently, in the last patch, are we sure this fixes all the \Drupal::logger occurances?

I'm also not sure if this is a bug or a task?

ravi.shankar’s picture

Issue tags: -Needs reroll
StatusFileSize
new7.4 KB
new5.19 KB

Added reroll of patch #28 on Drupal 9.5.x. and removed reroll tag.

borisson_’s picture

This patch does not apply to 10.x and since it introduces a ton of new deprecations I'm not sure if it should go in 9.5 with deprecations to be removed in 10.x or if it should go in both, with the intention to remove the deprecations in 11.x.

Let's start by fixing all the implementations left, I found those with rg \Drupal::logger

core/modules/locale/src/PoDatabaseWriter.php
240:        \Drupal::logger('locale')->error('Import of string "%string" was skipped because of disallowed or malformed HTML.', ['%string' => $translation]);

core/modules/system/src/Access/CronAccessCheck.php
24:      \Drupal::logger('cron')->notice('Cron could not run because an invalid key was used.');
28:      \Drupal::logger('cron')->notice('Cron could not run because the site is in maintenance mode.');

core/modules/migrate/src/MigrateMessage.php
27:    \Drupal::logger('migrate')->log($type, $message);

core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php
143:        \Drupal::logger('migrate_drupal_ui')->error($e->getMessage());
155:          \Drupal::logger('migrate_drupal_ui')->notice($message);
193:          \Drupal::logger('migrate_drupal_ui')->error('Operation on @migration failed', ['@migration' => $migration_name]);
198:          \Drupal::logger('migrate_drupal_ui')->error('Operation on @migration skipped due to unfulfilled dependencies', ['@migration' => $migration_name]);
215:        \Drupal::logger('migrate_drupal_ui')->error($message);

core/modules/filter/src/Element/ProcessedText.php
149:    return \Drupal::logger($channel);

core/modules/filter/src/Plugin/Filter/FilterNull.php
38:      \Drupal::logger('filter')->alert('Missing filter plugin: %filter.', ['%filter' => $plugin_id]);

core/modules/image/src/Entity/ImageStyle.php
324:      \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]);
334:        \Drupal::logger('image')->error('Cached image file %destination already exists. There may be an issue with your rewrite configuration.', ['%destination' => $derivative_uri]);

core/lib/Drupal/Core/Theme/ThemeManager.php
88:      $this->logger = \Drupal::logger('theme');

core/lib/Drupal/Core/Extension/ModuleInstaller.php
114:      $this->logger = \Drupal::logger('system');

core/lib/Drupal/Core/Entity/EntityDisplayBase.php
571:    return \Drupal::logger('system');
spokje’s picture

Version: 9.5.x-dev » 10.1.x-dev
Assigned: Unassigned » spokje
Category: Bug report » Task

Pretty sure it's too late for 9.5.x/10.0.x to introduce any more deprecations except for module/theme deprecations.
So moving this to 10.1.x.

Also pretty sure this is a task, since nothing is "broken".

spokje’s picture

Assigned: spokje » Unassigned

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

For many of these we should probably autoconfigure the loggers instead Loggers can be autoconfigured for service classes implementing \Psr\Log\LoggerAwareInterface

EDIT: I take it back. Most of these aren't in services, and if they are they use a different logger channel than what is autoconfigured. Perhaps we could make use of LoggerAwareInterface and LoggerAwareTrait though.

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.