Log.php

Go to the documentation of this file.
00001 <?php
00002 
00034 class Robo47_Log extends Zend_Log
00035 {
00036 
00041     protected $_defaultCategory = null;
00042 
00048     static public function factory($config = array())
00049     {
00050         if ($config instanceof Zend_Config) {
00051             $config = $config->toArray();
00052         }
00053 
00054         if (!is_array($config) || empty($config)) {
00055             $message = 'Configuration must be an array or ' .
00056                 'instance of Zend_Config';
00057             throw new Robo47_Log_Exception($message);
00058         }
00059 
00060         $log = new Robo47_Log();
00061 
00062         if (!is_array(current($config))) {
00063             $log->addWriter(current($config));
00064         } else {
00065             foreach ($config as $writer) {
00066                 $log->addWriter($writer);
00067             }
00068         }
00069 
00070         return $log;
00071     }
00072 
00078     public function getWriters()
00079     {
00080         return $this->_writers;
00081     }
00082 
00091     public function removeWriter($class)
00092     {
00093         foreach ($this->_writers as $key => $writer) {
00094             if (is_string($class)) {
00095                 if ($writer instanceof $class) {
00096                     unset($this->_writers[$key]);
00097                 }
00098             } elseif (is_object($class)) {
00099                 if ($writer === $class) {
00100                     unset($this->_writers[$key]);
00101                 }
00102             }
00103         }
00104         return $this;
00105     }
00106 
00115     public function removeFilter($class)
00116     {
00117         foreach ($this->_filters as $key => $filter) {
00118             if (is_string($class)) {
00119                 if ($filter instanceof $class) {
00120                     unset($this->_filters[$key]);
00121                 }
00122             } elseif (is_object($class)) {
00123                 if ($filter === $class) {
00124                     unset($this->_filters[$key]);
00125                 }
00126             }
00127         }
00128         return $this;
00129     }
00130 
00136     public function getFilters()
00137     {
00138         return $this->_filters;
00139     }
00140 
00148     public function log($message, $priority, $extras = null)
00149     {
00150         if (!isset($extras['category']) && $this->_defaultCategory !== null) {
00151             $extras['category'] = $this->getDefaultCategory();
00152         }
00153         parent::log($message, $priority, $extras);
00154     }
00155 
00161     public function getPriorities()
00162     {
00163         return $this->_priorities;
00164     }
00165 
00172     public function setDefaultCategory($category = null)
00173     {
00174         $this->_defaultCategory = $category;
00175         return $this;
00176     }
00177 
00183     public function getDefaultCategory()
00184     {
00185         return $this->_defaultCategory;
00186     }
00187 }