You are here

public function BufferLogger::log in TMGMT Translator Smartling 8.2

Same name and namespace in other branches
  1. 8.4 src/Logger/BufferLogger.php \Drupal\tmgmt_smartling\Logger\BufferLogger::log()
  2. 8.3 src/Logger/BufferLogger.php \Drupal\tmgmt_smartling\Logger\BufferLogger::log()

Logs with an arbitrary level.

Parameters

mixed $level:

string $message:

array $context:

Return value

void

Overrides LoggerTrait::log

File

src/Logger/BufferLogger.php, line 158

Class

BufferLogger
Class BufferLogger

Namespace

Drupal\tmgmt_smartling\Logger

Code

public function log($level, $message, array $context = []) {

  // Log only records from needed channels.
  if (empty($this->channels) || in_array($context['channel'], $this->channels)) {

    // Key "enable_smartling_logging" might be absent in provider settings
    // after module update. Consider this situation as "checked" by default.
    $enabled_logging = !isset($this->provider_settings['settings']['enable_smartling_logging']) || $this->provider_settings['settings']['enable_smartling_logging'] === TRUE;

    // Buffer log records with $this->log_level or lover.
    if ($level <= $this->log_level && !empty($this->provider_settings['settings']['project_id']) && $enabled_logging) {
      $this->buffer[] = [
        'level' => $level,
        'message' => $message,
        'context' => $context,
      ];

      // Flush buffer on overflow.
      if (count($this->buffer) == $this->buffer_limit) {
        $this
          ->flush();
      }
    }
  }
}