SyslogFormatter
extends LineFormatter
in package
Serializes a log message according to RFC 5424
Tags
Table of Contents
Constants
- SIMPLE_DATE = "Y-m-d\\TH:i:sP"
- SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
- FORMAT = "<%extra.priority%>1 %datetime% %extra.hostname% %extra.app-name% %extra.procid% %channel% %extra.structured-data% %level_name%: %message% %context% %extra%\n"
- NILVALUE = '-'
- SYSLOG_FACILITY_USER = 1
Properties
- $allowInlineLineBreaks : bool
- $basePath : string
- $dateFormat : string
- $format : string
- $ignoreEmptyContextAndExtra : bool
- $includeStacktraces : bool
- $indentStacktraces : string
- $maxLevelNameLength : int|null
- $maxNormalizeDepth : int
- $maxNormalizeItemCount : int
- $stacktracesParser : Closure|null
- $applicationName : string
- $hostname : string
- $procid : int
Methods
- __construct() : mixed
- addJsonEncodeOption() : $this
- allowInlineLineBreaks() : $this
- 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
- ignoreEmptyContextAndExtra() : $this
- includeStacktraces() : $this
- indentStacktraces() : $this
- Indent stack traces to separate them a bit from the main log record messages
- normalizeValue() : null|scalar|array<string|int, array<string|int, mixed>|scalar|null>
- Normalize an arbitrary value to a scalar|array|null
- removeJsonEncodeOption() : $this
- setBasePath() : $this
- Setting a base path will hide the base path from exception and stack trace file names to shorten them
- setDateFormat() : $this
- setJsonPrettyPrint() : $this
- Enables `json_encode` pretty print.
- setMaxLevelNameLength() : $this
- Allows cutting the level name to get fixed-length levels like INF for INFO, ERR for ERROR if you set this to 3 for example
- setMaxNormalizeDepth() : $this
- setMaxNormalizeItemCount() : $this
- stringify() : string
- convertToString() : string
- formatDate() : string
- normalize() : null|scalar|array<string|int, array<string|int, mixed>|scalar|null>
- normalizeException() : array<string|int, mixed>
- normalizeRecord() : array<string|int, array<string|int, mixed>|scalar|null>
- Provided as extension point
- replaceNewlines() : string
- toJson() : string
- Return the JSON representation of a value
- calculatePriority() : int
- formatExtra() : array<string, mixed>
Constants
SIMPLE_DATE
public
mixed
SIMPLE_DATE
= "Y-m-d\\TH:i:sP"
SIMPLE_FORMAT
public
mixed
SIMPLE_FORMAT
= "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
FORMAT
private
mixed
FORMAT
= "<%extra.priority%>1 %datetime% %extra.hostname% %extra.app-name% %extra.procid% %channel% %extra.structured-data% %level_name%: %message% %context% %extra%\n"
NILVALUE
private
mixed
NILVALUE
= '-'
SYSLOG_FACILITY_USER
private
mixed
SYSLOG_FACILITY_USER
= 1
Properties
$allowInlineLineBreaks
protected
bool
$allowInlineLineBreaks
$basePath
protected
string
$basePath
= ''
$dateFormat
protected
string
$dateFormat
$format
protected
string
$format
$ignoreEmptyContextAndExtra
protected
bool
$ignoreEmptyContextAndExtra
$includeStacktraces
protected
bool
$includeStacktraces
$indentStacktraces
protected
string
$indentStacktraces
= ''
$maxLevelNameLength
protected
int|null
$maxLevelNameLength
= null
$maxNormalizeDepth
protected
int
$maxNormalizeDepth
= 9
$maxNormalizeItemCount
protected
int
$maxNormalizeItemCount
= 1000
$stacktracesParser
protected
Closure|null
$stacktracesParser
= null
$applicationName
private
string
$applicationName
= self::NILVALUE
$hostname
private
string
$hostname
$procid
private
int
$procid
Methods
__construct()
public
__construct([string $applicationName = self::NILVALUE ]) : mixed
Parameters
- $applicationName : string = self::NILVALUE
addJsonEncodeOption()
public
addJsonEncodeOption(int $option) : $this
Parameters
- $option : int
Return values
$thisallowInlineLineBreaks()
public
allowInlineLineBreaks([bool $allow = true ]) : $this
Parameters
- $allow : bool = true
Return values
$thisformat()
Formats a log record.
public
format(LogRecord $record) : mixed
Parameters
- $record : LogRecord
-
A record to format
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
intignoreEmptyContextAndExtra()
public
ignoreEmptyContextAndExtra([bool $ignore = true ]) : $this
Parameters
- $ignore : bool = true
Return values
$thisincludeStacktraces()
public
includeStacktraces([bool $include = true ][, Closure|null $parser = null ]) : $this
Parameters
- $include : bool = true
- $parser : Closure|null = null
Return values
$thisindentStacktraces()
Indent stack traces to separate them a bit from the main log record messages
public
indentStacktraces(string $indent) : $this
Parameters
- $indent : string
-
The string used to indent, for example " "
Return values
$thisnormalizeValue()
Normalize an arbitrary value to a scalar|array|null
public
normalizeValue(mixed $data) : null|scalar|array<string|int, array<string|int, mixed>|scalar|null>
Parameters
- $data : mixed
Return values
null|scalar|array<string|int, array<string|int, mixed>|scalar|null>removeJsonEncodeOption()
public
removeJsonEncodeOption(int $option) : $this
Parameters
- $option : int
Return values
$thissetBasePath()
Setting a base path will hide the base path from exception and stack trace file names to shorten them
public
setBasePath([string $path = '' ]) : $this
Parameters
- $path : string = ''
Return values
$thissetDateFormat()
public
setDateFormat(string $dateFormat) : $this
Parameters
- $dateFormat : string
Return values
$thissetJsonPrettyPrint()
Enables `json_encode` pretty print.
public
setJsonPrettyPrint(bool $enable) : $this
Parameters
- $enable : bool
Return values
$thissetMaxLevelNameLength()
Allows cutting the level name to get fixed-length levels like INF for INFO, ERR for ERROR if you set this to 3 for example
public
setMaxLevelNameLength([int|null $maxLevelNameLength = null ]) : $this
Parameters
- $maxLevelNameLength : int|null = null
-
Maximum characters for the level name. Set null for infinite length (default)
Return values
$thissetMaxNormalizeDepth()
public
setMaxNormalizeDepth(int $maxNormalizeDepth) : $this
Parameters
- $maxNormalizeDepth : int
Return values
$thissetMaxNormalizeItemCount()
public
setMaxNormalizeItemCount(int $maxNormalizeItemCount) : $this
Parameters
- $maxNormalizeItemCount : int
Return values
$thisstringify()
public
stringify(mixed $value) : string
Parameters
- $value : mixed
Return values
stringconvertToString()
protected
convertToString(mixed $data) : string
Parameters
- $data : mixed
Return values
stringformatDate()
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>normalizeRecord()
Provided as extension point
protected
normalizeRecord(LogRecord $record) : array<string|int, array<string|int, mixed>|scalar|null>
Because normalize is called with sub-values of context data etc, normalizeRecord can be extended when data needs to be appended on the record array but not to other normalized data.
Parameters
- $record : LogRecord
Return values
array<string|int, array<string|int, mixed>|scalar|null>replaceNewlines()
protected
replaceNewlines(string $str) : string
Parameters
- $str : string
Return values
stringtoJson()
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
calculatePriority()
private
static calculatePriority(Level $level) : int
Parameters
- $level : Level
Return values
intformatExtra()
private
formatExtra(LogRecord $record) : array<string, mixed>
Parameters
- $record : LogRecord