GelfMessageFormatter
extends NormalizerFormatter
in package
Serializes a log message to GELF
Tags
Table of Contents
Constants
- SIMPLE_DATE = "Y-m-d\\TH:i:sP"
- DEFAULT_MAX_LENGTH = 32766
Properties
- $contextPrefix : string
- $dateFormat : string
- $extraPrefix : string
- $maxLength : int
- $maxNormalizeDepth : int
- $maxNormalizeItemCount : int
- $systemName : string
- $gelfVersion : int
- $jsonEncodeOptions : int
- $logLevels : array<int, int>
- Translates Monolog log levels to Graylog2 log priorities.
Methods
- __construct() : mixed
- addJsonEncodeOption() : self
- format() : mixed
- Formats a log record.
- formatBatch() : mixed
- Formats a set of log records.
- getDateFormat() : string
- getMaxNormalizeDepth() : int
- The maximum number of normalization levels to go through
- getMaxNormalizeItemCount() : int
- The maximum number of items to normalize per level
- removeJsonEncodeOption() : self
- setDateFormat() : self
- setJsonPrettyPrint() : self
- Enables `json_encode` pretty print.
- setMaxNormalizeDepth() : self
- setMaxNormalizeItemCount() : self
- formatDate() : string
- normalize() : null|scalar|array<string|int, array<string|int, mixed>|scalar|null>
- normalizeException() : array<string|int, mixed>
- toJson() : string
- Return the JSON representation of a value
Constants
SIMPLE_DATE
public
mixed
SIMPLE_DATE
= "Y-m-d\\TH:i:sP"
DEFAULT_MAX_LENGTH
protected
mixed
DEFAULT_MAX_LENGTH
= 32766
Properties
$contextPrefix
protected
string
$contextPrefix
a prefix for 'context' fields from the Monolog record (optional)
$dateFormat
protected
string
$dateFormat
$extraPrefix
protected
string
$extraPrefix
a prefix for 'extra' fields from the Monolog record (optional)
$maxLength
protected
int
$maxLength
max length per field
$maxNormalizeDepth
protected
int
$maxNormalizeDepth
= 9
$maxNormalizeItemCount
protected
int
$maxNormalizeItemCount
= 1000
$systemName
protected
string
$systemName
the name of the system for the Gelf log message
$gelfVersion
private
int
$gelfVersion
= 2
$jsonEncodeOptions
private
int
$jsonEncodeOptions
= \Monolog\Utils::DEFAULT_JSON_FLAGS
$logLevels
Translates Monolog log levels to Graylog2 log priorities.
private
array<int, int>
$logLevels
= [\Monolog\Logger::DEBUG => 7, \Monolog\Logger::INFO => 6, \Monolog\Logger::NOTICE => 5, \Monolog\Logger::WARNING => 4, \Monolog\Logger::ERROR => 3, \Monolog\Logger::CRITICAL => 2, \Monolog\Logger::ALERT => 1, \Monolog\Logger::EMERGENCY => 0]
Tags
Methods
__construct()
public
__construct([string|null $systemName = null ][, string|null $extraPrefix = null ][, string $contextPrefix = 'ctxt_' ][, int|null $maxLength = null ]) : mixed
Parameters
- $systemName : string|null = null
- $extraPrefix : string|null = null
- $contextPrefix : string = 'ctxt_'
- $maxLength : int|null = null
addJsonEncodeOption()
public
addJsonEncodeOption(int $option) : self
Parameters
- $option : int
Return values
selfformat()
Formats a log record.
public
format(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
Return values
mixed —The formatted record
formatBatch()
Formats a set of log records.
public
formatBatch(array<string|int, mixed> $records) : mixed
Parameters
- $records : array<string|int, mixed>
-
A set of records to format
Return values
mixed —The formatted set of records
getDateFormat()
public
getDateFormat() : string
Return values
stringgetMaxNormalizeDepth()
The maximum number of normalization levels to go through
public
getMaxNormalizeDepth() : int
Return values
intgetMaxNormalizeItemCount()
The maximum number of items to normalize per level
public
getMaxNormalizeItemCount() : int
Return values
intremoveJsonEncodeOption()
public
removeJsonEncodeOption(int $option) : self
Parameters
- $option : int
Return values
selfsetDateFormat()
public
setDateFormat(string $dateFormat) : self
Parameters
- $dateFormat : string
Return values
selfsetJsonPrettyPrint()
Enables `json_encode` pretty print.
public
setJsonPrettyPrint(bool $enable) : self
Parameters
- $enable : bool
Return values
selfsetMaxNormalizeDepth()
public
setMaxNormalizeDepth(int $maxNormalizeDepth) : self
Parameters
- $maxNormalizeDepth : int
Return values
selfsetMaxNormalizeItemCount()
public
setMaxNormalizeItemCount(int $maxNormalizeItemCount) : self
Parameters
- $maxNormalizeItemCount : int
Return values
selfformatDate()
protected
formatDate(DateTimeInterface $date) : string
Parameters
- $date : DateTimeInterface
Return values
stringnormalize()
protected
normalize(mixed $data[, int $depth = 0 ]) : null|scalar|array<string|int, array<string|int, mixed>|scalar|null>
Parameters
- $data : mixed
- $depth : int = 0
Return values
null|scalar|array<string|int, array<string|int, mixed>|scalar|null>normalizeException()
protected
normalizeException(Throwable $e[, int $depth = 0 ]) : array<string|int, mixed>
Parameters
- $e : Throwable
- $depth : int = 0
Return values
array<string|int, mixed>toJson()
Return the JSON representation of a value
protected
toJson(mixed $data[, bool $ignoreErrors = false ]) : string
Parameters
- $data : mixed
- $ignoreErrors : bool = false
Tags
Return values
string —if encoding fails and ignoreErrors is true 'null' is returned