Documentation

LogstashFormatter extends NormalizerFormatter
in package

Serializes a log message to Logstash Event Format

Tags
see
https://www.elastic.co/products/logstash
see
https://github.com/elastic/logstash/blob/master/logstash-core/src/main/java/org/logstash/Event.java
author

Tim Mower timothy.mower@gmail.com

Table of Contents

SIMPLE_DATE  = "Y-m-d\TH:i:sP"
$applicationName  : string
$contextKey  : string
$dateFormat  : string
$extraKey  : string
$maxNormalizeDepth  : int
$maxNormalizeItemCount  : int
$systemName  : string
$jsonEncodeOptions  : int
__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|scalar|null>
normalizeException()  : array<string|int, mixed>
toJson()  : string
Return the JSON representation of a value

Constants

Properties

$applicationName

protected string $applicationName

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

$contextKey

protected string $contextKey

the key for 'context' fields from the Monolog record

$extraKey

protected string $extraKey

the key for 'extra' fields from the Monolog record

$systemName

protected string $systemName

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

$jsonEncodeOptions

private int $jsonEncodeOptions = MonologUtils::DEFAULT_JSON_FLAGS

Methods

__construct()

public __construct(string $applicationName[, string|null $systemName = null ][, string $extraKey = 'extra' ][, string $contextKey = 'context' ]) : mixed
Parameters
$applicationName : string

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

$systemName : string|null = null

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

$extraKey : string = 'extra'

The key for extra keys inside logstash "fields", defaults to extra

$contextKey : string = 'context'

The key for context keys inside logstash "fields", defaults to context

Return values
mixed

addJsonEncodeOption()

public addJsonEncodeOption(int $option) : self
Parameters
$option : int
Return values
self

format()

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

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

removeJsonEncodeOption()

public removeJsonEncodeOption(int $option) : self
Parameters
$option : int
Return values
self

setDateFormat()

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

setJsonPrettyPrint()

Enables `json_encode` pretty print.

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

setMaxNormalizeDepth()

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

setMaxNormalizeItemCount()

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

formatDate()

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

normalize()

protected normalize(mixed $data, int $depth) : null|scalar|array<string|int, array|scalar|null>
Parameters
$data : mixed
$depth : int
Return values
null|scalar|array<string|int, array|scalar|null>

normalizeException()

protected normalizeException(Throwable $e, int $depth) : array<string|int, mixed>
Parameters
$e : Throwable
$depth : int
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
throws
RuntimeException

if encoding fails and errors are not ignored

Return values
string

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

Search results