You are here

public function BufferLogger::log in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 src/Logger/BufferLogger.php \Drupal\tmgmt_smartling\Logger\BufferLogger::log()
  2. 8.2 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 170

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.
    $logging_key_is_not_set = !isset($this->providerSettings['settings']['enable_smartling_logging']);
    $enabled_logging = $logging_key_is_not_set || $this->providerSettings['settings']['enable_smartling_logging'] === TRUE;

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

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