class JsonFileBackend extends FileBackend (View source)

A log backend which writes log entries into a file in an easy to parse json format

Properties

protected int $severityThreshold

One of the LOG_* constants. Anything below that will be filtered out.

from  AbstractBackend
protected bool $logIpAddress

Flag telling if the IP address of the current client (if available) should be logged.

from  AbstractBackend
protected array $severityLabels

An array of severity labels, indexed by their integer constant

from  FileBackend
protected string $logFileUrl from  FileBackend
protected int $maximumLogFileSize from  FileBackend
protected int $logFilesToKeep from  FileBackend
protected bool $createParentDirectories from  FileBackend
protected bool $logMessageOrigin from  FileBackend
protected resource|false $fileHandle from  FileBackend

Methods

__construct(mixed $options = [])

Constructs this log backend

void
setSeverityThreshold(int $severityThreshold)

The maximum severity to log, anything less severe will not be logged.

void
setLogIpAddress(bool $logIpAddress)

Enables or disables logging of IP addresses.

void
setLogFileURL(string $logFileUrl)

Sets URL pointing to the log file. Usually the full directory and the filename, however any valid stream URL is possible.

void
setCreateParentDirectories(bool $flag)

Sets the flag telling if parent directories in the path leading to the log file URL should be created if they don't exist.

void
setMaximumLogFileSize(int $maximumLogFileSize)

Sets the maximum log file size, if the logfile is bigger, a new one is started.

void
setLogFilesToKeep(int $logFilesToKeep)

If a new log file is started, keep this number of old log files.

void
setLogMessageOrigin(bool $flag)

If enabled, a hint about where the log message was created is added to the log file.

void
open()

Carries out all actions necessary to prepare the logging backend, such as opening the log file or opening a database connection.

void
rotateLogFile()

Rotate the log file and make sure the configured number of files is kept.

void
append(string $message, int $severity = LOG_INFO, mixed $additionalData = null, string $packageKey = null, string $className = null, string $methodName = null)

No description

void
close()

Carries out all actions necessary to cleanly close the logging backend, such as closing the log file or disconnecting from a database.

Details

__construct(mixed $options = [])

Constructs this log backend

Parameters

mixed $options

Configuration options - depends on the actual backend

void setSeverityThreshold(int $severityThreshold)

The maximum severity to log, anything less severe will not be logged.

Parameters

int $severityThreshold

One of the LOG_* constants

Return Value

void

void setLogIpAddress(bool $logIpAddress)

Enables or disables logging of IP addresses.

Parameters

bool $logIpAddress

Set to true to enable logging of IP address, or false to disable

Return Value

void

void setLogFileURL(string $logFileUrl)

Sets URL pointing to the log file. Usually the full directory and the filename, however any valid stream URL is possible.

Parameters

string $logFileUrl

URL pointing to the log file

Return Value

void

void setCreateParentDirectories(bool $flag)

Sets the flag telling if parent directories in the path leading to the log file URL should be created if they don't exist.

The default is to not create parent directories automatically.

Parameters

bool $flag

true if parent directories should be created

Return Value

void

void setMaximumLogFileSize(int $maximumLogFileSize)

Sets the maximum log file size, if the logfile is bigger, a new one is started.

Parameters

int $maximumLogFileSize

Maximum size in bytes

Return Value

void

See also

setLogFilesToKeep()

void setLogFilesToKeep(int $logFilesToKeep)

If a new log file is started, keep this number of old log files.

Parameters

int $logFilesToKeep

Number of old log files to keep

Return Value

void

See also

setMaximumLogFileSize()

void setLogMessageOrigin(bool $flag)

If enabled, a hint about where the log message was created is added to the log file.

Parameters

bool $flag

Return Value

void

void open()

Carries out all actions necessary to prepare the logging backend, such as opening the log file or opening a database connection.

Return Value

void

Exceptions

CouldNotOpenResourceException
FilesException

protected void rotateLogFile()

Rotate the log file and make sure the configured number of files is kept.

Return Value

void

void append(string $message, int $severity = LOG_INFO, mixed $additionalData = null, string $packageKey = null, string $className = null, string $methodName = null)

No description

Parameters

string $message

The message to log

int $severity

One of the LOG_* constants

mixed $additionalData

A variable containing more information about the event to be logged

string $packageKey

Key of the package triggering the log (determined automatically if not specified)

string $className

Name of the class triggering the log (determined automatically if not specified)

string $methodName

Name of the method triggering the log (determined automatically if not specified)

Return Value

void

void close()

Carries out all actions necessary to cleanly close the logging backend, such as closing the log file or disconnecting from a database.

Note: for this backend we do nothing here and rely on PHP to close the filehandle when the request ends. This is to allow full logging until request end.

Return Value

void