FileBackend
class FileBackend extends AbstractBackend (View source)
A log backend which writes log entries into a file
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 |
|
protected string | $logFileUrl | ||
protected int | $maximumLogFileSize | ||
protected int | $logFilesToKeep | ||
protected bool | $createParentDirectories | ||
protected bool | $logMessageOrigin | ||
protected resource|false | $fileHandle |
Methods
The maximum severity to log, anything less severe will not be logged.
Enables or disables logging of IP addresses.
Sets URL pointing to the log file. Usually the full directory and the filename, however any valid stream URL is possible.
Sets the flag telling if parent directories in the path leading to the log file URL should be created if they don't exist.
Sets the maximum log file size, if the logfile is bigger, a new one is started.
If a new log file is started, keep this number of old log files.
If enabled, a hint about where the log message was created is added to the log file.
Carries out all actions necessary to prepare the logging backend, such as opening the log file or opening a database connection.
Rotate the log file and make sure the configured number of files is kept.
Appends the given message along with the additional information into the log.
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
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.
The default is to not create parent directories automatically.
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.
protected 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)
Appends the given message along with the additional information into the log.
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.