Constants

SIMPLE_DATE

SIMPLE_DATE = "Y-m-d H:i:s"

V0

V0 = 0

V1

V1 = 1

Properties

$dateFormat

$dateFormat : 

Type

$systemName

$systemName : string

Type

string — the name of the system for the Logstash log message, used to fill the @source field

$applicationName

$applicationName : string

Type

string — an application name for the Logstash log message, used to fill the @type field

$extraPrefix

$extraPrefix : string

Type

string — a prefix for 'extra' fields from the Monolog record (optional)

$contextPrefix

$contextPrefix : string

Type

string — a prefix for 'context' fields from the Monolog record (optional)

$version

$version : integer

Type

integer — logstash format version to use

Methods

__construct()

__construct(string  $applicationName, string  $systemName = null, string  $extraPrefix = null, string  $contextPrefix = 'ctxt_', integer  $version = self::V0) 

Parameters

string $applicationName

the application that sends the data, used as the "type" field of logstash

string $systemName

the system/machine name, used as the "source" field of logstash, defaults to the hostname of the machine

string $extraPrefix

prefix for extra keys inside logstash "fields"

string $contextPrefix

prefix for context keys inside logstash "fields", defaults to ctxt_

integer $version

the logstash format version to use, defaults to 0

format()

format(array  $record) : mixed

Formats a log record.

Parameters

array $record

A record to format

Returns

mixed —

The formatted record

formatBatch()

formatBatch(array  $records) : mixed

Formats a set of log records.

Parameters

array $records

A set of records to format

Returns

mixed —

The formatted set of records

detectAndCleanUtf8()

detectAndCleanUtf8(  $data) 

Detect invalid UTF-8 string characters and convert to valid UTF-8.

Valid UTF-8 input will be left unmodified, but strings containing invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed original encoding of ISO-8859-15. This conversion may result in incorrect output if the actual encoding was not ISO-8859-15, but it will be clean UTF-8 output and will not rely on expensive and fragile detection algorithms.

Function converts the input in place in the passed variable so that it can be used as a callback for array_walk_recursive.

Parameters

$data

normalize()

normalize(  $data) 

Parameters

$data

normalizeException()

normalizeException(  $e) 

Parameters

$e

toJson()

toJson(mixed  $data, boolean  $ignoreErrors = false) : string

Return the JSON representation of a value

Parameters

mixed $data
boolean $ignoreErrors

Throws

\RuntimeException

if encoding fails and errors are not ignored

Returns

string

formatV0()

formatV0(array  $record) 

Parameters

array $record

formatV1()

formatV1(array  $record) 

Parameters

array $record

jsonEncode()

jsonEncode(mixed  $data) : string

Parameters

mixed $data

Returns

string —

JSON encoded data or null on failure

handleJsonError()

handleJsonError(integer  $code, mixed  $data) : string

Handle a json_encode failure.

If the failure is due to invalid string encoding, try to clean the input and encode again. If the second encoding attempt fails, the inital error is not encoding related or the input can't be cleaned then raise a descriptive exception.

Parameters

integer $code

return code of json_last_error function

mixed $data

data that was meant to be encoded

Throws

\RuntimeException

if failure can't be corrected

Returns

string —

JSON encoded data after error correction

throwEncodeError()

throwEncodeError(integer  $code, mixed  $data) 

Throws an exception according to a given code with a customized message

Parameters

integer $code

return code of json_last_error function

mixed $data

data that was meant to be encoded

Throws

\RuntimeException