Documentation

SyslogFormatter extends LineFormatter
in package

Serializes a log message according to RFC 5424

Tags
author

Dalibor Karlović dalibor.karlovic@sigwin.hr

author

Renat Gabdullin renatobyj@gmail.com

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_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"

Properties

$allowInlineLineBreaks

protected bool $allowInlineLineBreaks

$ignoreEmptyContextAndExtra

protected bool $ignoreEmptyContextAndExtra

$maxLevelNameLength

protected int|null $maxLevelNameLength = null

$stacktracesParser

protected Closure|null $stacktracesParser = null

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
$this

allowInlineLineBreaks()

public allowInlineLineBreaks([bool $allow = true ]) : $this
Parameters
$allow : bool = true
Return values
$this

format()

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

getMaxNormalizeDepth()

The maximum number of normalization levels to go through

public getMaxNormalizeDepth() : int
Return values
int

getMaxNormalizeItemCount()

The maximum number of items to normalize per level

public getMaxNormalizeItemCount() : int
Return values
int

ignoreEmptyContextAndExtra()

public ignoreEmptyContextAndExtra([bool $ignore = true ]) : $this
Parameters
$ignore : bool = true
Return values
$this

includeStacktraces()

public includeStacktraces([bool $include = true ][, Closure|null $parser = null ]) : $this
Parameters
$include : bool = true
$parser : Closure|null = null
Return values
$this

indentStacktraces()

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
$this

normalizeValue()

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
$this

setBasePath()

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
$this

setDateFormat()

public setDateFormat(string $dateFormat) : $this
Parameters
$dateFormat : string
Return values
$this

setJsonPrettyPrint()

Enables `json_encode` pretty print.

public setJsonPrettyPrint(bool $enable) : $this
Parameters
$enable : bool
Return values
$this

setMaxLevelNameLength()

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
$this

setMaxNormalizeDepth()

public setMaxNormalizeDepth(int $maxNormalizeDepth) : $this
Parameters
$maxNormalizeDepth : int
Return values
$this

setMaxNormalizeItemCount()

public setMaxNormalizeItemCount(int $maxNormalizeItemCount) : $this
Parameters
$maxNormalizeItemCount : int
Return values
$this

stringify()

public stringify(mixed $value) : string
Parameters
$value : mixed
Return values
string

convertToString()

protected convertToString(mixed $data) : string
Parameters
$data : mixed
Return values
string

formatDate()

protected formatDate(DateTimeInterface $date) : string
Parameters
$date : DateTimeInterface
Return values
string

normalize()

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
string

toJson()

Return the JSON representation of a value

protected toJson(mixed $data[, bool $ignoreErrors = false ]) : string
Parameters
$data : mixed
$ignoreErrors : bool = false
Tags
throws
RuntimeException

if encoding fails and errors are not ignored

Return values
string

if encoding fails and ignoreErrors is true 'null' is returned


        
On this page

Search results