Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created November 12, 2009 05:37
Show Gist options
  • Select an option

  • Save sminnee/232631 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/232631 to your computer and use it in GitHub Desktop.
<?php
/**
* Simple implementation of the SS_Log class that came in 2.4, for compatability with SilverStripe 2.3.
*/
class SS_Log {
protected static $writer;
protected static $priority_names = array(
3 => 'ERR',
4 => 'WARN',
5 => 'NOTICE',
GUARDIANLOGPAGEVIEW => 'PAGEVIEW',
);
static function add_writer($writer) {
self::$writer = $writer;
}
static function log($message, $priority) {
if(!self::$writer) return;
// Convert string priorities from 2.3 into numeric ones, used by the writer
if(is_string($priority)) {
$errNums = array(
'Error' => 3,
'Warning' => 4,
'Notice' => 5,
);
$priority = $errNums[$priority];
}
return self::$writer->_write(array(
'priorityName' => self::$priority_names[$priority],
'message' => $message,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment