Source for file Log.php
Documentation is available at Log.php
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
* @see Microsoft_AutoLoader
require_once dirname(__FILE__ ) . '/AutoLoader.php';
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Log.php 22632 2010-07-18 18:30:08Z ramon $
const EMERG = 0; // Emergency: system is unusable
const ALERT = 1; // Alert: action must be taken immediately
const CRIT = 2; // Critical: critical conditions
const ERR = 3; // Error: error conditions
const WARN = 4; // Warning: warning conditions
const NOTICE = 5; // Notice: normal but significant condition
const INFO = 6; // Informational: informational messages
const DEBUG = 7; // Debug: debug messages
* @var array of priorities where the keys are the
* priority numbers and the values are the priority names
* @var array of Microsoft_Log_Writer_Abstract
* @var array of Microsoft_Log_Filter_Interface
* @var array of extra log event
* Class constructor. Create a new logger
* @param Microsoft_Log_Writer_Abstract|null $writer default writer
public function __construct(Microsoft_Log_Writer_Abstract $writer = null)
$r = new ReflectionClass($this);
* Factory to construct the logger and one or more writers
* based on the configuration array
static public function factory($config = array())
if (!is_array($config) || empty($config)) {
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
foreach($config as $writer) {
$log->addWriter($writer);
* Construct a writer object based on a configuration array
* @param array $spec config array with writer spec
* @return Microsoft_Log_Writer_Abstract
: 'The specified writer';
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
if (isset ($config['filterName'])) {
$writer->addFilter($filter);
* Construct filter object from configuration array or Microsoft_Config object
* @return Microsoft_Log_Filter_Interface
: 'The specified filter';
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
* Construct a filter or writer from config
* @param string $type 'writer' of 'filter'
* @param string $namespace
if (!is_array($config) || empty($config)) {
require_once 'Microsoft/Log/Exception.php';
$params = isset ($config[ $type . 'Params' ]) ? $config[ $type . 'Params' ] : array();
$className = $this->getClassName($config, $type, $namespace);
require_once 'Microsoft/Loader.php';
Microsoft_Loader::loadClass($className);
$reflection = new ReflectionClass($className);
if (!$reflection->implementsInterface('Microsoft_Log_FactoryInterface')) {
require_once 'Zend/Log/Exception.php';
'Driver does not implement Microsoft_Log_FactoryInterface and can not be constructed from config.'
* Get the writer or filter full classname
* @param string $type filter|writer
* @param string $defaultNamespace
* @return string full classname
protected function getClassName($config, $type, $defaultNamespace)
if (!isset ($config[ $type . 'Name' ])) {
require_once 'Zend/Log/Exception.php';
$className = $config[ $type . 'Name' ];
$namespace = $defaultNamespace;
if (isset ($config[ $type . 'Namespace' ])) {
$namespace = $config[ $type . 'Namespace' ];
$fullClassName = $namespace . '_' . $className;
* Class destructor. Shutdown log writers
* Undefined method handler allows a shortcut:
* $log->priorityName('message')
* $log->log('message', Microsoft_Log::PRIORITY_NAME)
* @param string $method priority name
* @param string $params message to log
* @throws Microsoft_Log_Exception
public function __call($method, $params)
switch (count($params)) {
/** @see Microsoft_Log_Exception */
require_once 'Microsoft_/Log/Exception.php';
$this->log($message, $priority, $extras);
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
* Log a message at a priority
* @param string $message Message to log
* @param integer $priority Priority of message
* @param mixed $extras Extra information to log in event
* @throws Microsoft_Log_Exception
public function log($message, $priority, $extras = null)
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
// pack into event required by filters and writers
// Check to see if any extra information was passed
foreach ($extras as $key => $value) {
// abort if rejected by the global filters
if (! $filter->accept($event)) {
* @param string $name Name of priority
* @param integer $priority Numeric priority
// Priority names must be uppercase for predictability.
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
* Add a filter that will be applied before all log writers.
* Before a message will be received by any of the writers, it
* must be accepted by all filters added with this method.
* @param int|Microsoft_Log_Filter_Interface$filter
/** @see Microsoft_Log_Filter_Priority */
require_once 'Microsoft/Log/Filter/Priority.php';
} elseif ($filter instanceof Microsoft_Config || is_array($filter)) {
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
* Add a writer. A writer is responsible for taking a log
* message and writing it out to storage.
* @param mixed $writer Microsoft_Log_Writer_Abstract or Config array
/** @see Microsoft_Log_Exception */
require_once 'Microsoft/Log/Exception.php';
'Writer must be an instance of Microsoft_Log_Writer_Abstract'
. ' or you should pass a configuration array'
* Set an extra item to pass to the log writers.
* @param $name Name of the field
* @param $value Value of the field
|