class LoggerChannel implements LoggerChannelInterface (View source)

Defines a logger channel that most implementations will use.

Traits

LoggerTrait

Constants

MAX_CALL_DEPTH

Maximum call depth to self::log() for a single log message.

It's very easy for logging channel code to call out to other library code that will create log messages. In that case, we will recurse back in to LoggerChannel::log() multiple times while processing a single originating message. To prevent infinite recursion, we track the call depth and bail out at LoggerChannel::MAX_CALL_DEPTH iterations.

Properties

protected int $callDepth

Number of times LoggerChannel::log() has been called for a single message.

protected string $channel

The name of the channel of this logger instance.

protected array $levelTranslation

Map of PSR3 log constants to RFC 5424 log constants.

protected array $loggers

An array of arrays of \Psr\Log\LoggerInterface keyed by priority.

protected RequestStack $requestStack

The request stack object.

protected AccountInterface $currentUser

The current user object.

Methods

__construct(string $channel)

Constructs a LoggerChannel object.

log($level, $message, array $context = [])

{@inheritdoc}

setRequestStack(RequestStack $requestStack = NULL)

Sets the request stack.

setCurrentUser(AccountInterface $current_user = NULL)

Sets the current user.

setLoggers(array $loggers)

Sets the loggers for this channel.

addLogger(LoggerInterface $logger, int $priority = 0)

Adds a logger.

array
sortLoggers()

Sorts loggers according to priority.

Details

__construct(string $channel)

Constructs a LoggerChannel object.

Parameters

string $channel

The channel name for this instance.

log($level, $message, array $context = [])

{@inheritdoc}

Parameters

$level
$message
array $context

setRequestStack(RequestStack $requestStack = NULL)

Sets the request stack.

Parameters

RequestStack $requestStack

The current request object.

setCurrentUser(AccountInterface $current_user = NULL)

Sets the current user.

Parameters

AccountInterface $current_user

The current user object.

setLoggers(array $loggers)

Sets the loggers for this channel.

Parameters

array $loggers

An array of arrays of \Psr\Log\LoggerInterface keyed by priority.

addLogger(LoggerInterface $logger, int $priority = 0)

Adds a logger.

Parameters

LoggerInterface $logger

The PSR-3 logger to add.

int $priority

The priority of the logger being added.

protected array sortLoggers()

Sorts loggers according to priority.

Return Value

array

An array of sorted loggers by priority.