class SS_Log

Wrapper class for a logging handler like {@link Zend_Log} which takes a message (or a map of context variables) and sends it to one or more {@link 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 {@link SS_Log::add_writer()}

Example usage of logging errors by email notification: SS_Log::add_writer(new SS_LogEmailWriter('my@email.com'), 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('my@email.com'), 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. {@link 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('my@email.com'); $myEmailFormatter = new MyLogEmailFormatter(); $logEmailWriter->setFormatter($myEmailFormatter);

Constants

ERR

WARN

NOTICE

INFO

DEBUG

Properties

static string $logger_class Logger class to use.

Methods

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.

Details

at line 91
static object get_logger()

Get the logger currently in use, or create a new one if it doesn't exist.

Return Value

object

at line 112
static array get_writers()

Get all writers in use by the logger.

Return Value

array Collection of Zend_Log_Writer_Abstract instances

at line 119
static clear_writers()

Remove all writers currently in use.

at line 127
static remove_writer(object $writer)

Remove a writer instance from the logger.

Parameters

object $writer Zend_Log_Writer_Abstract instance

at line 140
static add_writer(object $writer, int $priority = null, string $comparison = '=')

Add a writer instance to the logger.

Parameters

object $writer Zend_Log_Writer_Abstract instance
int $priority Priority. Possible values: SS_Log::ERR, SS_Log::WARN or SS_Log::NOTICE
string $comparison Priority comparison operator. Acts on the integer values of the error levels, where more serious errors are lower numbers. By default this is "=", which means only the given priority will be logged. Set to "<=" if you want to track errors of at least the given priority.

at line 157
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).

Parameters

mixed $message Exception object or array of error context variables
int $priority Priority. Possible values: SS_Log::ERR, SS_Log::WARN or SS_Log::NOTICE
mixed $extras Extra information to log in event