-
Notifications
You must be signed in to change notification settings - Fork 0
Wodk Logger
A very simple logging class. The purpose of this class is to provide a simple log file that can then be displayed to an administrative user of the web app.
// Wodk_Logger needs the path to the log file, and it needs to be
// writable by the webserver.
$log = new Wodk_Logger('/var/www/example.log');
// Log simple
$log->log('A simple message.');
// Output:
// [Wed, Dec 31 1969 19:00:00 -0500] A simple message.
// Log complex
$log->log('error', 'An error.', 'Another error message.');
// Output:
// [Wed, Dec 31 1969 19:00:00 -0500] (error) An error.
// [Wed, Dec 31 1969 19:00:00 -0500] (error) Another error message.
// Using helper methods error, message and warn
$log->warn('Issue a warning on "%s".', 'this system');
// Output:
// [Wed, Dec 31 1969 19:00:00 -0500] (warning) Issue a warning on "this system".
- log
Record a particular message in the file. There are two ways to use it, simple or complex.
Simple logging takes one argument, the log message. Writes an entry to the log as
[$timestamp] message
.@param — The message.
@returns — Logger instance for chaining.
Complex logging takes at least two arguments. The first is the
type
of message. The remaining arguments are messages to log with thattype
. Writes as entry to the log as[$timestamp] ($type) $message
.@param — The type of message; typically
error
ormessage
. Any value is allowed.@param
...
— The messages to log as thistype
.@returns — Logger instance for chaining.
- error
Log an error message with [sprintf][] formatting. Writes an entry to the log as
[$timestamp] ($type) $message
.@param — The message to use formatting.
@param
...
— Arguments to format into the$format
string.@returns — Logger instance for chaining.
- message
Log a message with [sprintf][] formatting. Writes an entry to the log as
[$timestamp] ($type) $message
.@param — The mesage to use formatting.
@param
...
— Arguments to format into the$format
string.@returns — Logger instance for chaining.
- warn
Log a warning with [sprintf][] formatting. Writes an entry to the log as
[$timestamp] ($type) $message
.@param — The mesage to use formatting.
@param
...
— Arguments to format into the$format
string.@returns — Logger instance for chaining.
- read
Get the contents of the log, useful for passing from a Controller to a View.
@param $as_array — Return the log file as a
string
or anarray
. Defaults tostring
.@param $reverse — What order to return the array. The default is oldest first.
@returns — Either an array or string of the log file.
- writable
Checks if the log file is writable.
@returns — Boolean status of writability