trait LoggerChannelTrait (View source)

Wrapper methods for the logger factory service.

This utility trait should only be used in application-level code, such as classes that would implement ContainerInjectionInterface. Services registered in the Container should not use this trait but inject the appropriate service directly for easier testing.

Properties

protected LoggerChannelFactoryInterface $loggerFactory

The logger channel factory service.

Methods

LoggerInterface
getLogger(string $channel)

Gets the logger for a specific channel.

$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

Details

protected LoggerInterface getLogger(string $channel)

Gets the logger for a specific channel.

Require the use of injected services: https://www.drupal.org/node/2733703

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

$this setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

Parameters

LoggerChannelFactoryInterface $logger_factory

The logger channel factory service.

Return Value

$this