class LoggerChannel in TMGMT Translator Smartling 8.3
Same name and namespace in other branches
- 8.4 modules/tmgmt_smartling_log_settings/src/Logger/LoggerChannel.php \Drupal\tmgmt_smartling_log_settings\Logger\LoggerChannel
Defines a logger channel that most implementations will use.
Same as core's LoggerChannel but with "suppress logging" feature.
Hierarchy
- class \Drupal\Core\Logger\LoggerChannel implements LoggerChannelInterface uses \Psr\Log\LoggerTrait- class \Drupal\tmgmt_smartling_log_settings\Logger\LoggerChannel
 
Expanded class hierarchy of LoggerChannel
File
- modules/tmgmt_smartling_log_settings/ src/ Logger/ LoggerChannel.php, line 14 
Namespace
Drupal\tmgmt_smartling_log_settings\LoggerView source
class LoggerChannel extends LoggerChannelCore {
  /**
   * @var array|mixed
   */
  private $severity_mapping;
  /**
   * {@inheritdoc}
   */
  public function __construct($channel) {
    $severity_mapping =& drupal_static(get_called_class());
    if (!isset($severity_mapping)) {
      $config = \Drupal::configFactory()
        ->getEditable('tmgmt_smartling_log_settings.settings')
        ->get('severity_mapping');
      $severity_mapping = Yaml::decode($config);
    }
    $this->severity_mapping = $severity_mapping;
    parent::__construct($channel);
  }
  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = []) {
    if ($this->callDepth == self::MAX_CALL_DEPTH) {
      return;
    }
    $this->callDepth++;
    // Merge in defaults.
    $context += [
      'channel' => $this->channel,
      'link' => '',
      'user' => NULL,
      'uid' => 0,
      'request_uri' => '',
      'referer' => '',
      'ip' => '',
      'timestamp' => time(),
    ];
    // Some context values are only available when in a request context.
    if ($this->requestStack && ($request = $this->requestStack
      ->getCurrentRequest())) {
      $context['request_uri'] = $request
        ->getUri();
      $context['referer'] = $request->headers
        ->get('Referer', '');
      $context['ip'] = $request
        ->getClientIP();
      try {
        if ($this->currentUser) {
          $context['user'] = $this->currentUser;
          $context['uid'] = $this->currentUser
            ->id();
        }
      } catch (\Exception $e) {
        // An exception might be thrown if the database connection is not
        // available or due to another unexpected reason. It is more important
        // to log the error that we already have so any additional exceptions
        // are ignored.
      }
    }
    if (is_string($level)) {
      // Convert to integer equivalent for consistency with RFC 5424.
      $level = $this->levelTranslation[$level];
    }
    // Call all available loggers.
    foreach ($this
      ->sortLoggers() as $logger) {
      $logger_class = get_class($logger);
      // Log records into Smartling anyway. BufferLogger is subscribed ONLY
      // to Smartling related channels (smartling_api, tmgmt_smartling and
      // tmgmt_extension_suit). On/Off logic happens inside BufferLogger::log().
      if ($logger_class == 'Drupal\\tmgmt_smartling\\Logger\\BufferLogger') {
        $logger
          ->log($level, $message, $context);
      }
      else {
        $config_level = !empty($this->severity_mapping[$this->channel]) ? $this->levelTranslation[$this->severity_mapping[$this->channel]] : RfcLogLevel::DEBUG;
        if (!empty($this->severity_mapping[$this->channel])) {
          if ($level <= $config_level) {
            $logger
              ->log($level, $message, $context);
          }
        }
        else {
          $logger
            ->log($level, $message, $context);
        }
      }
    }
    $this->callDepth--;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| LoggerChannel:: | protected | property | Number of times LoggerChannel::log() has been called for a single message. | |
| LoggerChannel:: | protected | property | The name of the channel of this logger instance. | |
| LoggerChannel:: | protected | property | The current user object. | |
| LoggerChannel:: | protected | property | Map of PSR3 log constants to RFC 5424 log constants. | |
| LoggerChannel:: | protected | property | An array of arrays of \Psr\Log\LoggerInterface keyed by priority. | |
| LoggerChannel:: | protected | property | The request stack object. | |
| LoggerChannel:: | private | property | ||
| LoggerChannel:: | public | function | Adds a logger. Overrides LoggerChannelInterface:: | |
| LoggerChannel:: | public | function | Logs with an arbitrary level. Overrides LoggerChannel:: | |
| LoggerChannel:: | constant | Maximum call depth to self::log() for a single log message. | ||
| LoggerChannel:: | public | function | Sets the current user. Overrides LoggerChannelInterface:: | |
| LoggerChannel:: | public | function | Sets the loggers for this channel. Overrides LoggerChannelInterface:: | |
| LoggerChannel:: | public | function | Sets the request stack. Overrides LoggerChannelInterface:: | |
| LoggerChannel:: | protected | function | Sorts loggers according to priority. | |
| LoggerChannel:: | public | function | Constructs a LoggerChannel object Overrides LoggerChannel:: | 
