LoggerChannelInterface.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Drupal\Core\Logger;
  3. use Drupal\Core\Session\AccountInterface;
  4. use Psr\Log\LoggerInterface;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. /**
  7. * Logger channel interface.
  8. *
  9. * This interface defines the full behavior of the central Drupal logger
  10. * facility. However, when writing code that does logging, use the generic
  11. * \Psr\Log\LoggerInterface for typehinting instead (you shouldn't need the
  12. * methods here).
  13. *
  14. * To add a new logger to the system, implement \Psr\Log\LoggerInterface and
  15. * add a service for that class to a services.yml file tagged with the 'logger'
  16. * tag. The default logger channel implementation will call the log() method
  17. * of every logger service with some useful data set in the $context argument
  18. * of log(): request_uri, referer, ip, user, uid.
  19. *
  20. * SECURITY NOTE: the caller might also set a 'link' in the $context array
  21. * which will be printed as-is by the dblog module under an "operations"
  22. * header. Usually this is a "view", "edit" or similar relevant link. Make sure
  23. * to use proper, secure link generation facilities; some are listed below.
  24. *
  25. * @see \Drupal\Core\Logger\RfcLoggerTrait
  26. * @see \Psr\Log\LoggerInterface
  27. * @see \Drupal\Core\Logger\\LoggerChannelFactoryInterface
  28. * @see \Drupal\Core\Utility\LinkGeneratorInterface
  29. * @see \Drupal\Core\Link::fromTextAndUrl()
  30. * @see \Drupal\Core\Entity\EntityInterface::link()
  31. */
  32. interface LoggerChannelInterface extends LoggerInterface {
  33. /**
  34. * Sets the request stack.
  35. *
  36. * @param \Symfony\Component\HttpFoundation\RequestStack|null $requestStack
  37. * The current request object.
  38. */
  39. public function setRequestStack(RequestStack $requestStack = NULL);
  40. /**
  41. * Sets the current user.
  42. *
  43. * @param \Drupal\Core\Session\AccountInterface|null $current_user
  44. * The current user object.
  45. */
  46. public function setCurrentUser(AccountInterface $current_user = NULL);
  47. /**
  48. * Sets the loggers for this channel.
  49. *
  50. * @param array $loggers
  51. * An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
  52. */
  53. public function setLoggers(array $loggers);
  54. /**
  55. * Adds a logger.
  56. *
  57. * @param \Psr\Log\LoggerInterface $logger
  58. * The PSR-3 logger to add.
  59. * @param int $priority
  60. * The priority of the logger being added.
  61. */
  62. public function addLogger(LoggerInterface $logger, $priority = 0);
  63. }