LogglyFormatter
extends JsonFormatter
in package
Encodes message information into JSON in a format compatible with Loggly.
Tags
Table of Contents
Constants
- BATCH_MODE_JSON = 1
- BATCH_MODE_NEWLINES = 2
- SIMPLE_DATE = "Y-m-d\\TH:i:sP"
Properties
- $appendNewline : bool
- $basePath : string
- $batchMode : self::BATCH_MODE_*
- $dateFormat : string
- $ignoreEmptyContextAndExtra : bool
- $includeStacktraces : bool
- $maxNormalizeDepth : int
- $maxNormalizeItemCount : int
Methods
- __construct() : mixed
- Overrides the default batch mode to new lines for compatibility with the Loggly bulk API.
- addJsonEncodeOption() : $this
- format() : mixed
- Formats a log record.
- formatBatch() : mixed
- Formats a set of log records.
- getBatchMode() : int
- The batch mode option configures the formatting style for multiple records. By default, multiple records will be formatted as a JSON-encoded array. However, for compatibility with some API endpoints, alternative styles are available.
- getDateFormat() : string
- getMaxNormalizeDepth() : int
- The maximum number of normalization levels to go through
- getMaxNormalizeItemCount() : int
- The maximum number of items to normalize per level
- includeStacktraces() : $this
- isAppendingNewlines() : bool
- True if newlines are appended to every formatted record
- 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.
- setMaxNormalizeDepth() : $this
- setMaxNormalizeItemCount() : $this
- formatBatchJson() : string
- Return a JSON-encoded array of records.
- formatBatchNewlines() : string
- Use new lines to separate records instead of a JSON-encoded array.
- formatDate() : string
- normalize() : null|scalar|array<string|int, array<string|int, mixed>|scalar|null|object>|object
- Normalizes given $data.
- normalizeException() : array<string|int, mixed>
- Normalizes given exception with or without its own stack trace based on `includeStacktraces` property.
- normalizeRecord() : array<string|int, array<string|int, mixed>|scalar|null>
- Appends the 'timestamp' parameter for indexing by Loggly.
- toJson() : string
- Return the JSON representation of a value
Constants
BATCH_MODE_JSON
public
mixed
BATCH_MODE_JSON
= 1
BATCH_MODE_NEWLINES
public
mixed
BATCH_MODE_NEWLINES
= 2
SIMPLE_DATE
public
mixed
SIMPLE_DATE
= "Y-m-d\\TH:i:sP"
Properties
$appendNewline
protected
bool
$appendNewline
$basePath
protected
string
$basePath
= ''
$batchMode
protected
self::BATCH_MODE_*
$batchMode
$dateFormat
protected
string
$dateFormat
$ignoreEmptyContextAndExtra
protected
bool
$ignoreEmptyContextAndExtra
$includeStacktraces
protected
bool
$includeStacktraces
= false
$maxNormalizeDepth
protected
int
$maxNormalizeDepth
= 9
$maxNormalizeItemCount
protected
int
$maxNormalizeItemCount
= 1000
Methods
__construct()
Overrides the default batch mode to new lines for compatibility with the Loggly bulk API.
public
__construct([int $batchMode = self::BATCH_MODE_NEWLINES ][, bool $appendNewline = false ]) : mixed
Parameters
- $batchMode : int = self::BATCH_MODE_NEWLINES
- $appendNewline : bool = false
addJsonEncodeOption()
public
addJsonEncodeOption(int $option) : $this
Parameters
- $option : int
Return values
$thisformat()
Formats a log record.
public
format(LogRecord $record) : mixed
Parameters
- $record : LogRecord
-
A record to format
Tags
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
Tags
Return values
mixed —The formatted set of records
getBatchMode()
The batch mode option configures the formatting style for multiple records. By default, multiple records will be formatted as a JSON-encoded array. However, for compatibility with some API endpoints, alternative styles are available.
public
getBatchMode() : int
Return values
intgetDateFormat()
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
intincludeStacktraces()
public
includeStacktraces([bool $include = true ]) : $this
Parameters
- $include : bool = true
Return values
$thisisAppendingNewlines()
True if newlines are appended to every formatted record
public
isAppendingNewlines() : bool
Return values
boolnormalizeValue()
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
$thissetMaxNormalizeDepth()
public
setMaxNormalizeDepth(int $maxNormalizeDepth) : $this
Parameters
- $maxNormalizeDepth : int
Return values
$thissetMaxNormalizeItemCount()
public
setMaxNormalizeItemCount(int $maxNormalizeItemCount) : $this
Parameters
- $maxNormalizeItemCount : int
Return values
$thisformatBatchJson()
Return a JSON-encoded array of records.
protected
formatBatchJson(array<string|int, mixed> $records) : string
Parameters
- $records : array<string|int, mixed>
Tags
Return values
stringformatBatchNewlines()
Use new lines to separate records instead of a JSON-encoded array.
protected
formatBatchNewlines(array<string|int, mixed> $records) : string
Parameters
- $records : array<string|int, mixed>
Tags
Return values
stringformatDate()
protected
formatDate(DateTimeInterface $date) : string
Parameters
- $date : DateTimeInterface
Return values
stringnormalize()
Normalizes given $data.
protected
normalize(mixed $data[, int $depth = 0 ]) : null|scalar|array<string|int, array<string|int, mixed>|scalar|null|object>|object
Parameters
- $data : mixed
- $depth : int = 0
Return values
null|scalar|array<string|int, array<string|int, mixed>|scalar|null|object>|objectnormalizeException()
Normalizes given exception with or without its own stack trace based on `includeStacktraces` property.
protected
normalizeException(Throwable $e[, int $depth = 0 ]) : array<string|int, mixed>
Parameters
- $e : Throwable
- $depth : int = 0
Tags
Return values
array<string|int, mixed>normalizeRecord()
Appends the 'timestamp' parameter for indexing by Loggly.
protected
normalizeRecord(LogRecord $record) : array<string|int, array<string|int, mixed>|scalar|null>
Parameters
- $record : LogRecord
Tags
Return values
array<string|int, array<string|int, mixed>|scalar|null>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