ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Formatter\GelfMessageFormatter Class Reference

Serializes a log message to GELF. More...

+ Inheritance diagram for Monolog\Formatter\GelfMessageFormatter:
+ Collaboration diagram for Monolog\Formatter\GelfMessageFormatter:

Public Member Functions

 __construct ($systemName=null, $extraPrefix=null, $contextPrefix='ctxt_', $maxLength=null)
 
 format (array $record)
 {Formats a log record.
Parameters
array$recordA record to format
Returns
mixed The formatted record
} More...
 
- Public Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 __construct ($dateFormat=null)
 
 format (array $record)
 {Formats a log record.
Parameters
array$recordA record to format
Returns
mixed The formatted record
} More...
 
 formatBatch (array $records)
 {Formats a set of log records.
Parameters
array$recordsA set of records to format
Returns
mixed The formatted set of records
} More...
 
 detectAndCleanUtf8 (&$data)
 Detect invalid UTF-8 string characters and convert to valid UTF-8. More...
 

Data Fields

const DEFAULT_MAX_LENGTH = 32766
 
- Data Fields inherited from Monolog\Formatter\NormalizerFormatter
const SIMPLE_DATE = "Y-m-d H:i:s"
 

Protected Attributes

 $systemName
 
 $extraPrefix
 
 $contextPrefix
 
 $maxLength
 
- Protected Attributes inherited from Monolog\Formatter\NormalizerFormatter
 $dateFormat
 

Private Attributes

 $logLevels
 Translates Monolog log levels to Graylog2 log priorities. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\Formatter\NormalizerFormatter
 normalize ($data, $depth=0)
 
 normalizeException ($e)
 
 toJson ($data, $ignoreErrors=false)
 Return the JSON representation of a value. More...
 

Detailed Description

Serializes a log message to GELF.

See also
http://www.graylog2.org/about/gelf
Author
Matt Lehner mlehn.nosp@m.er@g.nosp@m.mail..nosp@m.com

Definition at line 23 of file GelfMessageFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Formatter\GelfMessageFormatter::__construct (   $systemName = null,
  $extraPrefix = null,
  $contextPrefix = 'ctxt_',
  $maxLength = null 
)

Member Function Documentation

◆ format()

Monolog\Formatter\GelfMessageFormatter::format ( array  $record)

{Formats a log record.

Parameters
array$recordA record to format
Returns
mixed The formatted record
}

Implements Monolog\Formatter\FormatterInterface.

Definition at line 75 of file GelfMessageFormatter.php.

References $key, $message, and Monolog\Formatter\NormalizerFormatter\toJson().

76  {
77  $record = parent::format($record);
78 
79  if (!isset($record['datetime'], $record['message'], $record['level'])) {
80  throw new \InvalidArgumentException('The record should at least contain datetime, message and level keys, '.var_export($record, true).' given');
81  }
82 
83  $message = new Message();
84  $message
85  ->setTimestamp($record['datetime'])
86  ->setShortMessage((string) $record['message'])
87  ->setHost($this->systemName)
88  ->setLevel($this->logLevels[$record['level']]);
89 
90  // message length + system name length + 200 for padding / metadata
91  $len = 200 + strlen((string) $record['message']) + strlen($this->systemName);
92 
93  if ($len > $this->maxLength) {
94  $message->setShortMessage(substr($record['message'], 0, $this->maxLength));
95  }
96 
97  if (isset($record['channel'])) {
98  $message->setFacility($record['channel']);
99  }
100  if (isset($record['extra']['line'])) {
101  $message->setLine($record['extra']['line']);
102  unset($record['extra']['line']);
103  }
104  if (isset($record['extra']['file'])) {
105  $message->setFile($record['extra']['file']);
106  unset($record['extra']['file']);
107  }
108 
109  foreach ($record['extra'] as $key => $val) {
110  $val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
111  $len = strlen($this->extraPrefix . $key . $val);
112  if ($len > $this->maxLength) {
113  $message->setAdditional($this->extraPrefix . $key, substr($val, 0, $this->maxLength));
114  break;
115  }
116  $message->setAdditional($this->extraPrefix . $key, $val);
117  }
118 
119  foreach ($record['context'] as $key => $val) {
120  $val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
121  $len = strlen($this->contextPrefix . $key . $val);
122  if ($len > $this->maxLength) {
123  $message->setAdditional($this->contextPrefix . $key, substr($val, 0, $this->maxLength));
124  break;
125  }
126  $message->setAdditional($this->contextPrefix . $key, $val);
127  }
128 
129  if (null === $message->getFile() && isset($record['context']['exception']['file'])) {
130  if (preg_match("/^(.+):([0-9]+)$/", $record['context']['exception']['file'], $matches)) {
131  $message->setFile($matches[1]);
132  $message->setLine($matches[2]);
133  }
134  }
135 
136  return $message;
137  }
catch(Exception $e) $message
toJson($data, $ignoreErrors=false)
Return the JSON representation of a value.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $contextPrefix

Monolog\Formatter\GelfMessageFormatter::$contextPrefix
protected

◆ $extraPrefix

Monolog\Formatter\GelfMessageFormatter::$extraPrefix
protected

◆ $logLevels

Monolog\Formatter\GelfMessageFormatter::$logLevels
private
Initial value:

Translates Monolog log levels to Graylog2 log priorities.

Definition at line 50 of file GelfMessageFormatter.php.

◆ $maxLength

Monolog\Formatter\GelfMessageFormatter::$maxLength
protected

◆ $systemName

Monolog\Formatter\GelfMessageFormatter::$systemName
protected

◆ DEFAULT_MAX_LENGTH

const Monolog\Formatter\GelfMessageFormatter::DEFAULT_MAX_LENGTH = 32766

Definition at line 25 of file GelfMessageFormatter.php.


The documentation for this class was generated from the following file: