Documentation

JsonFormatter extends NormalizerFormatter
in package

Encodes whatever record data is passed to it as json

This can be useful to log to databases or remote APIs

Tags
author

Jordi Boggiano j.boggiano@seld.be

Table of Contents

Constants

BATCH_MODE_JSON  = 1
BATCH_MODE_NEWLINES  = 2
SIMPLE_DATE  = "Y-m-d H:i:s"

Properties

$appendNewline  : mixed
$batchMode  : mixed
$dateFormat  : mixed
$includeStacktraces  : bool

Methods

__construct()  : mixed
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.
includeStacktraces()  : mixed
isAppendingNewlines()  : bool
True if newlines are appended to every formatted record
formatBatchJson()  : string
Return a JSON-encoded array of records.
formatBatchNewlines()  : string
Use new lines to separate records instead of a JSON-encoded array.
normalize()  : mixed
Normalizes given $data.
normalizeException()  : array<string|int, mixed>
Normalizes given exception with or without its own stack trace based on `includeStacktraces` property.
toJson()  : string
Return the JSON representation of a value

Constants

Properties

$includeStacktraces

protected bool $includeStacktraces = false

Methods

__construct()

public __construct([int $batchMode = self::BATCH_MODE_JSON ][, bool $appendNewline = true ]) : mixed
Parameters
$batchMode : int = self::BATCH_MODE_JSON
$appendNewline : bool = true

format()

Formats a log record.

public format(array<string|int, mixed> $record) : mixed
Parameters
$record : array<string|int, mixed>

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

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
int

includeStacktraces()

public includeStacktraces([bool $include = true ]) : mixed
Parameters
$include : bool = true

isAppendingNewlines()

True if newlines are appended to every formatted record

public isAppendingNewlines() : bool
Return values
bool

formatBatchJson()

Return a JSON-encoded array of records.

protected formatBatchJson(array<string|int, mixed> $records) : string
Parameters
$records : array<string|int, mixed>
Return values
string

formatBatchNewlines()

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>
Return values
string

normalize()

Normalizes given $data.

protected normalize(mixed $data[, mixed $depth = 0 ]) : mixed
Parameters
$data : mixed
$depth : mixed = 0

normalizeException()

Normalizes given exception with or without its own stack trace based on `includeStacktraces` property.

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

        
On this page

Search results