/**
  * {@inheritdoc}
  */
 public function get($channel)
 {
     if (!isset($this->channels[$channel])) {
         $instance = new LoggerChannel($channel);
         // Pass the loggers to the channel.
         $instance->setLoggers($this->loggers);
         $this->channels[$channel] = $instance;
     }
     return $this->channels[$channel];
 }
Ejemplo n.º 2
0
 /**
  * Test to make sure we don't log when we're not configured to.
  *
  * @covers ::log
  * @covers ::__construct
  */
 public function testLoggingOff()
 {
     $config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('debugging.log' => FALSE)));
     $cas_helper = new CasHelper($config_factory, $this->urlGenerator, $this->connection, $this->loggerFactory, $this->session);
     $this->loggerChannel->expects($this->never())->method('log');
     $cas_helper->log('This is a test, but should not be logged as such.');
 }
 /**
  * Tests LoggerChannel::addLoggers().
  *
  * @covers ::addLogger
  * @covers ::sortLoggers
  */
 public function testSortLoggers()
 {
     $channel = new LoggerChannel($this->randomMachineName());
     $index_order = '';
     for ($i = 0; $i < 4; $i++) {
         $logger = $this->getMock('Psr\\Log\\LoggerInterface');
         $logger->expects($this->once())->method('log')->will($this->returnCallback(function () use($i, &$index_order) {
             // Append the $i to the index order, so that we know the order that
             // loggers got called with.
             $index_order .= $i;
         }));
         $channel->addLogger($logger, $i);
     }
     $channel->log(rand(0, 7), $this->randomMachineName());
     // Ensure that the logger added in the end fired first.
     $this->assertEquals($index_order, '3210');
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function get($channel)
 {
     if (!isset($this->channels[$channel])) {
         $instance = new LoggerChannel($channel);
         // If we have a container set the request_stack and current_user services
         // on the channel. It is up to the channel to determine if there is a
         // current request.
         if ($this->container) {
             $instance->setRequestStack($this->container->get('request_stack'));
             $instance->setCurrentUser($this->container->get('current_user'));
         }
         // Pass the loggers to the channel.
         $instance->setLoggers($this->loggers);
         $this->channels[$channel] = $instance;
     }
     return $this->channels[$channel];
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = [])
 {
     $this->logs[] = ['level' => $level, 'message' => $message, 'context' => $context];
     // Log message only if rules logging setting is enabled.
     if ($this->config->get('debug_log')) {
         if ($this->levelTranslation[$this->config->get('log_errors')] >= $this->levelTranslation[$level]) {
             parent::log($level, $message, $context);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Log information to the logger.
  *
  * Only log supplied information to the logger if module is configured to do
  * so, otherwise do nothing.
  *
  * @param string $message
  *   The message to log.
  */
 public function log($message)
 {
     if ($this->settings->get('debugging.log') == TRUE) {
         $this->loggerChannel->log(RfcLogLevel::DEBUG, $message);
     }
 }