Perforce Chronicle 2012.2/486814
API Documentation
|
Provides a static log method that will write to a Zend_Log instance set via setLogger(). More...
Static Public Member Functions | |
static | getLogger () |
Get the logger to use when logging. | |
static | hasLogger () |
Determine if a logger has been set. | |
static | log ($message, $priority=null, $extras=null) |
Log a message at a priority using the zend log instance set via setLogger. | |
static | logException ($message, $exception) |
Log an exception. | |
static | setLogger ($logger) |
Set the logger to use when logging. | |
Public Attributes | |
const | ALERT = 1 |
const | CRIT = 2 |
const | DEBUG = 7 |
const | EMERG = 0 |
const | ERR = 3 |
const | INFO = 6 |
const | NOTICE = 5 |
const | WARN = 4 |
Static Protected Attributes | |
static | $_logger = null |
Provides a static log method that will write to a Zend_Log instance set via setLogger().
This gives predictable, singleton access to a system-wide logger.
static P4_Log::getLogger | ( | ) | [static] |
Get the logger to use when logging.
Zend_Log_Exception | if there is no log instance set. |
{ if (!static::$_logger instanceof Zend_Log) { throw new P4_Exception( "Cannot get logger. No logger has been set." ); } return static::$_logger; }
static P4_Log::hasLogger | ( | ) | [static] |
Determine if a logger has been set.
{ try { static::getLogger(); return true; } catch (P4_Exception $e) { return false; } }
static P4_Log::log | ( | $ | message, |
$ | priority = null , |
||
$ | extras = null |
||
) | [static] |
Log a message at a priority using the zend log instance set via setLogger.
If no logger has been set, fails quietly.
string | $message | Message to log |
integer | $priority | Priority of message |
mixed | $extras | Extra information to log in event |
{ try { if ($priority === null) { $priority = self::INFO; } static::getLogger()->log($message, $priority, $extras); } catch (Exception $e) { // don't let failure to log stop execution. } }
static P4_Log::logException | ( | $ | message, |
$ | exception | ||
) | [static] |
Log an exception.
Logs a caller provided message (to give context) with the exception message and type (as an error). Also logs a backtrace (at debug priority).
string | $message | Message to log with the exception. |
integer | $exception | The exception that occured. |
{ // if caller failed to provide an exception object, just log // the message. if (!$exception instanceof Exception) { static::log($message, static::ERR); return; } static::log( $message . " " . get_class($exception) . ": " . $exception->getMessage(), static::ERR ); static::log( "Backtrace:\n" . $exception->getTraceAsString(), static::DEBUG ); }
static P4_Log::setLogger | ( | $ | logger | ) | [static] |
Set the logger to use when logging.
null | Zend_Log | $logger | a zend log instance to log to or null to clear. |
InvalidArgumentException | if the given log is not a valid zend log. |
{ if ($logger !== null && !$logger instanceof Zend_Log) { throw new InvalidArgumentException( "Cannot set logger. The given logger is not a valid zend log instance." ); } static::$_logger = $logger; }
P4_Log::$_logger = null [static, protected] |
const P4_Log::ALERT = 1 |
const P4_Log::CRIT = 2 |
const P4_Log::DEBUG = 7 |
const P4_Log::EMERG = 0 |
const P4_Log::ERR = 3 |
const P4_Log::INFO = 6 |
const P4_Log::NOTICE = 5 |
const P4_Log::WARN = 4 |