You are here

public function LagoonLogstashFormatter::format in Lagoon Logs 7

File

lib/LagoonLogstashFormatter.php, line 23

Class

LagoonLogstashFormatter

Code

public function format($record) {
  if (empty($record['datetime'])) {
    $record['datetime'] = gmdate('c');
  }
  $message = array(
    '@timestamp' => $record['datetime'],
    '@version' => 1,
    'host' => $this->systemName,
  );
  if (isset($record['message'])) {
    $message['message'] = $record['message'];
  }
  if (isset($record['channel'])) {
    $message['type'] = $record['channel'];
    $message['channel'] = $record['channel'];
  }
  if (isset($record['level_name'])) {
    $message['level'] = $record['level_name'];
  }
  if ($this->applicationName) {
    $message['type'] = $this->applicationName;
  }
  if (!empty($record['extra'])) {
    foreach ($record['extra'] as $key => $val) {
      $message[$key] = $val;
    }
  }
  return $message;
}