LoggerChannelInterface.php 2.34 KB
Newer Older
1
2
3
4
5
6
<?php

namespace Drupal\Core\Logger;

use Drupal\Core\Session\AccountInterface;
use Psr\Log\LoggerInterface;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
9
10

/**
 * Logger channel interface.
11
12
13
14
15
16
17
18
19
20
 *
 * 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
21
 * of log(): request_uri, referer, ip, uid, link, channel, timestamp.
22
23
24
25
26
27
28
29
30
31
 *
 * 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.
 *
 * @see \Drupal\Core\Logger\RfcLoggerTrait
 * @see \Psr\Log\LoggerInterface
 * @see \Drupal\Core\Logger\\LoggerChannelFactoryInterface
 * @see \Drupal\Core\Utility\LinkGeneratorInterface
32
 * @see \Drupal\Core\Link::fromTextAndUrl()
33
 * @see \Drupal\Core\Entity\EntityInterface::link()
34
35
36
37
 */
interface LoggerChannelInterface extends LoggerInterface {

  /**
38
   * Sets the request stack.
39
   *
40
   * @param \Symfony\Component\HttpFoundation\RequestStack|null $requestStack
41
42
   *   The current request object.
   */
43
  public function setRequestStack(RequestStack $requestStack = NULL);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

  /**
   * 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);

}