Problem/Motivation

Loggers in Drupal are typically called with the factory pattern. However, \Drupal\csp\Controller\ReportUri calls the logger service with a direct call to the logger.channel.csp service.

Proposed resolution

Replace the direct call to the logger.channel.csp service with a call to the config.factory service.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review
StatusFileSize
new1.49 KB

Attached patch replaces the direct call to the logger.channel.csp service with a call to the config.factory service.

gapple’s picture

Component: Code » Documentation
Priority: Normal » Minor
Status: Needs review » Needs work

The comment updates are good, but the code change is unnecessary.

The logger.channel.csp service extends from the logger.channel_base service:

  logger.channel.csp:
    parent: logger.channel_base
    arguments: ['csp']

The logger.channel_base service from core is a factory definition:

  logger.channel_base:
    abstract: true
    class: Drupal\Core\Logger\LoggerChannel
    factory: logger.factory:get

Other logger channels in core also use the same pattern so they can be injected directly as services:

logger.channel.default:
    parent: logger.channel_base
    arguments: ['system']
  logger.channel.php:
    parent: logger.channel_base
    arguments: ['php']
  logger.channel.image:
    parent: logger.channel_base
    arguments: ['image']
  logger.channel.cron:
    parent: logger.channel_base
    arguments: ['cron']
  logger.channel.file:
    class: Drupal\Core\Logger\LoggerChannel
    factory: logger.factory:get
    arguments: ['file']
  logger.channel.form:
    parent: logger.channel_base
    arguments: ['form']

  • gapple committed 3e9bf9a on 8.x-1.x
    Issue #3004054 by idebr, gapple: Update report controller code comments
    
gapple’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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