rendered paste body<?php /*** @package jelix* @subpackage utils* @version $Id$* @author Yannick Le Guédart* @copyright 2006 Yannick Le Guédart* @link http://www.jelix.org*/define('JLOG_FATAL', 1); /** System is unusable */define('JLOG_ERROR', 2); /** Error conditions */define('JLOG_WARNING', 4); /** Warning conditions */define('JLOG_NOTICE', 8); /** Normal but significant */define('JLOG_INFO', 16); /** Informational */define('JLOG_DEBUG', 32); /** Debug-level messages */define('JLOG_ALL', bindec('111111')); /** All messages */define('JLOG_NONE', bindec('000000')); /** No message *//** * The jLogger class * * @package jLogger */class jLog_{ /** * The array of error labels * * @var array * @access protected */ private static $_levelLabel = array ( JLOG_FATAL => "FATAL_", JLOG_ERROR => "ERROR_", JLOG_WARNING => "WARN__", JLOG_NOTICE => "NOTICE", JLOG_INFO => "INFO__", JLOG_DEBUG => "DEBUG_"); /** * The array of used loggers * * @var array * @access protected */ protected static $loggers = array (); /** * Adding a logger * * @param object $logger * @return object $logger * @access public */ static public function addLogger ($logger) { self::$loggers[] = $logger; return $logger; } /** * Resetting the logger array * * @return boolean * @access public */ static public function resetLoggers () { self::$loggers = array(); } /** * Setting the global level for all the loggers * * @return integer * @access public */ static public function setAllLevel ($newLevel) { if (is_int ($newLevel)) { foreach (self::$loggers as $log) { $log->setLevel ($newLevel); } } } /** * Inserting a log in the loggers * * @param string * @param integer * @return void * @access public */ static protected function call ($message, $level) { foreach(self::$loggers as $log) { if ($log->getLevel () & $level) { $messageLog = strtr( $log->getPattern (), array ( '%date%' => date("Y-m-d H:i:s"), '%message%' => $message, '%label%' => self::$_levelLabel[$level] ) ); switch ($level) { case JLOG_FATAL: $log->fatal ($messageLog); break; case JLOG_ERROR: $log->error ($messageLog); break; case JLOG_WARNING: $log->warning ($messageLog); break; case JLOG_NOTICE: $log->notice ($messageLog); break; case JLOG_INFO: $log->info ($messageLog); break; case JLOG_DEBUG: $log->debug ($messageLog); break; } } } } /** * Inserting a fatal log * * @param string * @return void * @access public */ static public function fatal ($message) { self::call ($message, JLOG_FATAL); } /** * Inserting a error log * * @param string * @return void * @access public */ static public function error ($message) { self::call ($message, JLOG_ERROR); } /** * Inserting a warning log * * @param string * @return void * @access public */ static public function warning ($message) { self::call ($message, JLOG_WARNING); } /** * Inserting a notice log * * @param string * @return void * @access public */ static public function notice ($message) { self::call ($message, JLOG_NOTICE); } /** * Inserting an info log * * @param string * @return void * @access public */ static public function info ($message) { self::call ($message, JLOG_INFO); } /** * Inserting a debug log * * @param string * @return void * @access public */ static public function debug ($message) { self::call ($message, JLOG_DEBUG); }}abstract class jLogger { /** * The log level * * @var integer * @access protected */ private $_level = JLOG_ALL; /** * The output pattern * * @var string * @access private */ private $_pattern = "%date% [%label%] %message%\n"; /** * Pattern getter * * @return string * @access public */ public function getPattern () { return $this->_pattern; } /** * Level getter * * @return integer * @access public */ public function getLevel () { return $this->_level; } /** * Level setter * * @param integer * @return integer * @access public */ public function setLevel ($level) { if (is_int ($level)) { $this->_level = $level; } return $this->_level; } public abstract function fatal ($message); public abstract function error ($message); public abstract function warning ($message); public abstract function notice ($message); public abstract function info ($message); public abstract function debug ($message); public abstract function clear ();}class jFileLogger extends jLogger{ private $_fileName = ""; /** * Class constructor * * @param string * @param string * @return void * @access public */ public function __construct ($fileName, $pattern = null) { $this->_fileName = $fileName; if (! file_exists ($this->_fileName)) { if (! @touch ($this->_fileName)) { throw new Exception ("Can't create Log file [$fileName]"); } } if (! is_null ($pattern)) { $this->_pattern = $pattern; } } /** * Inserting a fatal log * * @param string * @return void * @access public */ public function fatal ($message) { error_log ($message, 3, $this->_fileName); } /** * Inserting an error log * * @param string * @return void * @access public */ public function error ($message) { error_log ($message, 3, $this->_fileName); } /** * Inserting a warning log * * @param string * @return void * @access public */ public function warning ($message) { error_log ($message, 3, $this->_fileName); } /** * Inserting a notice log * * @param string * @return void * @access public */ public function notice ($message) { error_log ($message, 3, $this->_fileName); } /** * Inserting a info log * * @param string * @return void * @access public */ public function info ($message) { error_log ($message, 3, $this->_fileName); } /** * Inserting a debug log * * @param string * @return void * @access public */ public function debug ($message) { error_log ($message, 3, $this->_fileName); } public function clear() {} }?>