systemLog

Main system log handling class. This is used for all logging with in the framework. systemLog supports any number of systemLogWriters. The only requirement is that each writer have a unique target or log name. Certain log writers can only be used once (systemLogWriterScreen and systemLogWriterCli).

systemLog is a static object with only a single instance ever used.

If called directly: systemLog::getInstance()->log() a default log file is created in the current log folder with a name and path based on the current script. By default messages are filtered from ALWAYS to WARNING.

Additional static methods are included to make it more convenient to log messages at a specific level.

Finally, a configurable source can be defined that will be prepended to all log messages. The source is an object containing various key or key value pairs of data. See systemLogSource for more details.

// log a message
systemLog::message('this will always be logged');

// log a warning
systemLog::warning('this is a warning');

// set-up a custom log writer and then write to it
$oWriter = new systemLogWriterFile(
		'my/log/file/inlogs/folder.log',
		new systemLogFilter(
			systemLogLevel::ALWAYS, systemLogLevel::WARNING
		)
);
systemLog::getInstance($oWriter)->setLogLevel(systemLogLevel::WARNING);
systemLog::message('this will now go to the custom file');

As each writer can have a custom filter and log file it is possible to set up multiple writers to capture specific error messages or events. An example would be capturing all critical errors and emailing them to a set of devs who are charged with bug-fixing.

The global log level is set within this class by calling setLogLevel to one of the defined constants in systemLogLevel.

Note: It is possible to end up in a situation where no log information can be recorded as the log writer is failing. In a production environment this will cause the app to fail silently with possible errors being generated in the PHP error log (if it has been enabled!). In development (or non-production) environments the specific exception will be caught and displayed along with a trace.


Methods

private __construct()

Returns new instance of systemLog

public static getInstance([$inWriter = false])

Returns the current active instance of systemLog or creates a new one

public static errorHandler($inErrno, $inErrmsg, $inFilename, $inLinenum, $inVars)

Static method to be used with set_error_handler

public static exceptionHandler($inException)

Exception handler to be used with set_exception_handler()

private static _buildStackTrace($inTrace)

Converts a back trace into an array of strings

public static message($inMessage)

Log a message to the current log instance

public static always($inMessage)

Log a message to the current log instance

public static critical($inMessage)

Log a message to the current log instance

public static debug($inMessage)

Log a message to the current log instance

public static error($inMessage)

Log a message to the current log instance

public static info($inMessage)

Log a message to the current log instance

public static notice($inMessage)

Log a message to the current log instance

public static warning($inMessage)

Log a message to the current log instance

public static auditSuccess($inMessage)

Log a message to the current log instance

public static auditFailure($inMessage)

Log a message to the current log instance

public log($inMessage, [$inLogLevel = null])

Sends the message to the writers for logging.

public countWriters()

Returns the number of writers in the system

public getWriter($inUniqueId)

Returns writer with $inUniqueId

public getWriters()

Returns all writers

public setWriter($oWriter)

Adds a new writer

public removeWriter($inUniqueId)

Remove the writer with $inUniqueId, can also be instance of the writer

public resetWriters()

Removes all writers from systemLog

public getLogLevel()

Return log level

public setLogLevel($inLogLevel)

Set log level

public getSource()

Returns $_Source

public setSource($inSource)

Sets $_Source to $inSource

public getUseExtendedExceptionData()

Returns true if exception handler should report extended data

public setUseExtendedExceptionData([$inStatus = true])

Sets if exception handler should report extended data (true) or not (false)


Inherited Methods

<  1  >