Problem/Motivation

Loggers can be other things than core's LoggerChannelInterface. For example if you use the monolog library.

Generally we say that loggers are LoggerInterface (from psr/log) in core.

This is not the case for core/modules/migrate_drupal/src/FieldDiscovery.php

This in turn crashes things that invoke this class, when the logger is not set as a LoggerChannel. A typical error would then be:

TypeError: Argument 3 passed to Drupal\migrate_drupal\FieldDiscovery::__construct() must implement interface Drupal\Core\Logger\LoggerChannelInterface, instance of Psr\Log\NullLogger given, called in /my-site/drupal/core/lib/Drupal/Component/DependencyInjection/Container.php on line 277 in Drupal\migrate_drupal\FieldDiscovery->__construct() (line 110 of /my-site/drupal/core/modules/migrate_drupal/src/FieldDiscovery.php).

Proposed resolution

Replace it with LoggerInterface. In fact, in core, this is the only place we specify the type to be LoggerChannelInterface (did a quick search).

Remaining tasks

Create a patch and commit.

User interface changes

None

API changes

Well I guess theoretically, but LoggerChannelInterface extends LoggerInterface

Data model changes

None

Release notes snippet

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eiriksm created an issue. See original summary.

eiriksm’s picture

Status: Active » Needs review
FileSize
3.85 KB
longwave’s picture

Status: Needs review » Reviewed & tested by the community

This looks fine. No API change as LoggerChannelInterface already extends LoggerInterface, so this just fixes the bug and any existing callers will still work.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This looks good but unfortunately we need a 9.0.x version too so we can commit this there too. core/modules/migrate_drupal/src/FieldDiscovery.php has diverged.

ravi.shankar’s picture

Here I have done patch #2 on Drupal 9.0.x

longwave’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 0c3891e and pushed to 9.0.x. Thanks!
Committed and pushed 0a7c6dc9cd to 8.9.x and 3416efa646 to 8.8.x. Thanks!

Backported to 8.8.x as this is a simple widening of an constructor.

  • alexpott committed 0c3891e on 9.0.x
    Issue #3101818 by eiriksm, ravi.shankar, longwave: Allow other loggers...

  • alexpott committed 0a7c6dc on 8.9.x
    Issue #3101818 by eiriksm, ravi.shankar, longwave: Allow other loggers...

  • alexpott committed 3416efa on 8.8.x
    Issue #3101818 by eiriksm, ravi.shankar, longwave: Allow other loggers...

Status: Fixed » Closed (fixed)

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