interface LoggerChannelInterface

Same name in other branches
  1. 9 core/lib/Drupal/Core/Logger/LoggerChannelInterface.php \Drupal\Core\Logger\LoggerChannelInterface
  2. 10 core/lib/Drupal/Core/Logger/LoggerChannelInterface.php \Drupal\Core\Logger\LoggerChannelInterface
  3. 11.x core/lib/Drupal/Core/Logger/LoggerChannelInterface.php \Drupal\Core\Logger\LoggerChannelInterface

Logger channel interface.

This interface defines the full behavior of the central Drupal logger facility. However, when writing code that does logging, use the generic \Psr\Log\LoggerInterface for typehinting instead (you shouldn't need the methods here).

To add a new logger to the system, implement \Psr\Log\LoggerInterface and add a service for that class to a services.yml file tagged with the 'logger' tag. The default logger channel implementation will call the log() method of every logger service with some useful data set in the $context argument of log(): request_uri, referer, ip, user, uid.

SECURITY NOTE: the caller might also set a 'link' in the $context array which will be printed as-is by the dblog module under an "operations" header. Usually this is a "view", "edit" or similar relevant link. Make sure to use proper, secure link generation facilities; some are listed below.

Hierarchy

Expanded class hierarchy of LoggerChannelInterface

All classes that implement LoggerChannelInterface

See also

\Drupal\Core\Logger\RfcLoggerTrait

\Psr\Log\LoggerInterface

\Drupal\Core\Logger\\LoggerChannelFactoryInterface

\Drupal\Core\Utility\LinkGeneratorInterface

\Drupal\Core\Link::fromTextAndUrl()

\Drupal\Core\Entity\EntityInterface::link()

3 files declare their use of LoggerChannelInterface
FieldDiscoveryTest.php in core/modules/migrate_drupal/tests/src/Unit/FieldDiscoveryTest.php
MigrateTestBase.php in core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
StorageCopyTraitTest.php in core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php

File

core/lib/Drupal/Core/Logger/LoggerChannelInterface.php, line 35

Namespace

Drupal\Core\Logger
View source
interface LoggerChannelInterface extends LoggerInterface {
    
    /**
     * Sets the request stack.
     *
     * @param \Symfony\Component\HttpFoundation\RequestStack|null $requestStack
     *   The current request object.
     */
    public function setRequestStack(RequestStack $requestStack = NULL);
    
    /**
     * Sets the current user.
     *
     * @param \Drupal\Core\Session\AccountInterface|null $current_user
     *   The current user object.
     */
    public function setCurrentUser(AccountInterface $current_user = NULL);
    
    /**
     * Sets the loggers for this channel.
     *
     * @param array $loggers
     *   An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
     */
    public function setLoggers(array $loggers);
    
    /**
     * Adds a logger.
     *
     * @param \Psr\Log\LoggerInterface $logger
     *   The PSR-3 logger to add.
     * @param int $priority
     *   The priority of the logger being added.
     */
    public function addLogger(LoggerInterface $logger, $priority = 0);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
LoggerChannelInterface::addLogger public function Adds a logger. 1
LoggerChannelInterface::setCurrentUser public function Sets the current user. 1
LoggerChannelInterface::setLoggers public function Sets the loggers for this channel. 1
LoggerChannelInterface::setRequestStack public function Sets the request stack. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.