Perforce Chronicle 2012.2/486814
API Documentation

P4_Log Class Reference

Provides a static log method that will write to a Zend_Log instance set via setLogger(). More...

Inheritance diagram for P4_Log:
P4Cms_Log

List of all members.

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

Detailed Description

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.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static P4_Log::getLogger ( ) [static]

Get the logger to use when logging.

Returns:
Zend_Log the zend log instance to log to.
Exceptions:
Zend_Log_Exceptionif 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.

Returns:
bool true if a logger has been set; false otherwise.
    {
        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.

Parameters:
string$messageMessage to log
integer$priorityPriority of message
mixed$extrasExtra 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).

Parameters:
string$messageMessage to log with the exception.
integer$exceptionThe 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.

Parameters:
null | Zend_Log$loggera zend log instance to log to or null to clear.
Exceptions:
InvalidArgumentExceptionif 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;
    }

Member Data Documentation

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

The documentation for this class was generated from the following file: