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

public static 
object
get_logger()

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

public static 
array
get_writers()

Get all writers in use by the logger.

public static 
clear_writers()

Remove all writers currently in use.

public static 
remove_writer(object $writer)

Remove a writer instance from the logger.

public static 
add_writer(object $writer, int $priority = null, string $comparison = '=')

Add a writer instance to the logger.

public static 
log(mixed $message, int $priority, mixed $extras = null)

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.

Return Value

object

static array get_writers()

Get all writers in use by the logger.

Return Value

array

Collection of Zend_Log_Writer_Abstract instances

static clear_writers()

Remove all writers currently in use.

static remove_writer(object $writer)

Remove a writer instance from the logger.

Parameters

object $writer

Zend_Log_Writer_Abstract instance

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.

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