SS_Log
class SS_Log (View source)
Wrapper class for a logging handler like Zend_Log which takes a message (or a map of context variables) and sends it to one or more Zend_Log_Writer_Abstract subclasses for output.
These priorities are currently supported:
- SS_Log::ERR
- SS_Log::WARN
- SS_Log::NOTICE
You can add an error writer by calling SS_Log::add_writer()
Example usage of logging errors by email notification:
SS_Log::add_writer(new SS_LogEmailWriter('[email protected]'), SS_Log::ERR);
Example usage of logging errors by file:
SS_Log::add_writer(new SS_LogFileWriter('/var/log/silverstripe/errors.log'), SS_Log::ERR);
Example usage of logging at warnings and errors by setting the priority to '<=':
SS_Log::add_writer(new SS_LogEmailWriter('[email protected]'), SS_Log::WARN, '<=');
Each writer object can be assigned a formatter. The formatter is responsible for formatting the message before giving it to the writer. SS_LogErrorEmailFormatter is such an example that formats errors into HTML for human readability in an email client.
Formatters are added to writers like this:
$logEmailWriter = new SS_LogEmailWriter('[email protected]');
$myEmailFormatter = new MyLogEmailFormatter();
$logEmailWriter->setFormatter($myEmailFormatter);
Constants
ERR |
|
WARN |
|
NOTICE |
|
INFO |
|
DEBUG |
|
Properties
public static | string | $logger_class | Logger class to use. |
|
protected static | object | $logger | ||
protected static | array | $log_globals |
Methods
Get the logger currently in use, or create a new one if it doesn't exist.
Add a writer instance to the logger.
Dispatch a message by priority level.
Details
static object
get_logger()
Get the logger currently in use, or create a new one if it doesn't exist.
static array
get_writers()
Get all writers in use by the logger.
static
clear_writers()
Remove all writers currently in use.
static
remove_writer(object $writer)
Remove a writer instance from the logger.
static
add_writer(object $writer, int $priority = null, string $comparison = '=')
Add a writer instance to the logger.
static
log(mixed $message, int $priority, mixed $extras = null)
Dispatch a message by priority level.
The message parameter can be either a string (a simple error message), or an array of variables. The latter is useful for passing along a list of debug information for the writer to handle, such as error code, error line, error context (backtrace).