* Log::add_writer(new LogEmailWriter('my@email.com'), Log::ERR);
*
*
* Example usage of logging errors by file:
*
* Log::add_writer(new LogFileWriter('/var/log/silverstripe/errors.log'), Log::ERR);
*
*
* Example usage of logging at warnings and errors by setting the priority to '<=':
*
* Log::add_writer(new LogEmailWriter('my@email.com'), 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 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 LogEmailWriter('my@email.com');
* $myEmailFormatter = new MyLogEmailFormatter();
* $logEmailWriter->setFormatter($myEmailFormatter);
*
*/
class Log
{
const ERR = 'error';
const WARN = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
/**
* Get the logger currently in use, or create a new one if it doesn't exist.
*
* @deprecated 4.0..5.0
* @return LoggerInterface
*/
public static function get_logger() {
Deprecation::notice('5.0', 'Use Injector::inst()->get(\'Logger\') instead');
return Injector::inst()->get('Logger');
}
/**
* 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).
*
* @param mixed $message Exception object or array of error context variables
* @param string $priority Priority. Possible values: Log::ERR, Log::WARN, Log::NOTICE, Log::INFO or Log::DEBUG
*
* @deprecated 4.0.0:5.0.0 Use Injector::inst()->get('Logger')->log($priority, $message) instead
*/
public static function log($message, $priority) {
Deprecation::notice('5.0', 'Use Injector::inst()->get(\'Logger\')->log($priority, $message) instead');
Injector::inst()->get('Logger')->log($priority, $message);
}
}