\Monolog\FormatterLogglyFormatter

Encodes message information into JSON in a format compatible with Loggly.

This can be useful to log to databases or remote APIs

Summary

Methods
Properties
Constants
__construct()
getBatchMode()
isAppendingNewlines()
format()
formatBatch()
includeStacktraces()
detectAndCleanUtf8()
No public properties found
BATCH_MODE_JSON
BATCH_MODE_NEWLINES
SIMPLE_DATE
formatBatchJson()
formatBatchNewlines()
normalize()
normalizeException()
toJson()
$batchMode
$appendNewline
$includeStacktraces
$dateFormat
N/A
jsonEncode()
handleJsonError()
throwEncodeError()
No private properties found
N/A

Constants

BATCH_MODE_JSON

BATCH_MODE_JSON = 1

BATCH_MODE_NEWLINES

BATCH_MODE_NEWLINES = 2

SIMPLE_DATE

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

Properties

$batchMode

$batchMode : 

Type

$appendNewline

$appendNewline : 

Type

$includeStacktraces

$includeStacktraces : boolean

Type

boolean

$dateFormat

$dateFormat : 

Type

Methods

__construct()

__construct(integer  $batchMode = self::BATCH_MODE_NEWLINES, boolean  $appendNewline = false) 

Overrides the default batch mode to new lines for compatibility with the Loggly bulk API.

Parameters

integer $batchMode
boolean $appendNewline

getBatchMode()

getBatchMode() : integer

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.

Returns

integer

isAppendingNewlines()

isAppendingNewlines() : boolean

True if newlines are appended to every formatted record

Returns

boolean

format()

format(array  $record) : mixed

Appends the 'timestamp' parameter for indexing by Loggly.

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

includeStacktraces()

includeStacktraces(boolean  $include = true) 

Parameters

boolean $include

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

formatBatchJson()

formatBatchJson(array  $records) : string

Return a JSON-encoded array of records.

Parameters

array $records

Returns

string

formatBatchNewlines()

formatBatchNewlines(array  $records) : string

Use new lines to separate records instead of a JSON-encoded array.

Parameters

array $records

Returns

string

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

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