You are here

public function LagoonLogsLogger::log in Lagoon Logs 8

Overrides RfcLoggerTrait::log

File

src/Logger/LagoonLogsLogger.php, line 106

Class

LagoonLogsLogger

Namespace

Drupal\lagoon_logs\Logger

Code

public function log($level, $message, array $context = []) {
  global $base_url;
  $logger = new Logger(self::LAGOON_LOGS_MONOLOG_CHANNEL_NAME);
  $formatter = new LogstashFormatter($this->logFullIdentifier, null, null, 'ctxt_', 1);
  $connectionString = sprintf("udp://%s:%s", $this->hostName, $this->hostPort);
  $udpHandler = new SocketHandler($connectionString);

  // Monolog has a change waiting for release that allows us to have large UDP packets.
  $udpHandler
    ->setChunkSize(self::LAGOON_LOGS_DEFAULT_CHUNK_SIZE_BYTES);
  $udpHandler
    ->setFormatter($formatter);
  $logger
    ->pushHandler($udpHandler);
  $message_placeholders = $this->parser
    ->parseMessagePlaceholders($message, $context);
  $message = strip_tags(empty($message_placeholders) ? $message : strtr($message, $message_placeholders));
  $processorData = $this
    ->transformDataForProcessor($level, $message, $context, $base_url);
  $logger
    ->pushProcessor(new LagoonLogsLogProcessor($processorData));
  try {
    $logger
      ->log($this
      ->mapRFCtoMonologLevels($level), $message);
  } catch (\Exception $exception) {
  }
}