123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- /**
- * log4php is a PHP port of the log4j java logging package.
- *
- * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
- * <p>Design, strategies and part of the methods documentation are developed by log4j team
- * (Ceki Gülcü as log4j project founder and
- * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
- *
- * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
- * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
- *
- * <p>This software is published under the terms of the LGPL License
- * a copy of which has been included with this distribution in the LICENSE file.</p>
- *
- * @package log4php
- */
- /**
- * @ignore
- */
- if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
-
- /**
- */
- require_once(LOG4PHP_DIR . '/LoggerLog.php');
- define('LOG4PHP_LEVEL_OFF_INT', 2147483647);
- define('LOG4PHP_LEVEL_FATAL_INT', 50000);
- define('LOG4PHP_LEVEL_ERROR_INT', 40000);
- define('LOG4PHP_LEVEL_WARN_INT', 30000);
- define('LOG4PHP_LEVEL_INFO_INT', 20000);
- define('LOG4PHP_LEVEL_DEBUG_INT', 10000);
- define('LOG4PHP_LEVEL_ALL_INT', -2147483648);
- /**
- * Defines the minimum set of levels recognized by the system, that is
- * <i>OFF</i>, <i>FATAL</i>, <i>ERROR</i>,
- * <i>WARN</i>, <i>INFO</i, <i>DEBUG</i> and
- * <i>ALL</i>.
- *
- * <p>The <i>LoggerLevel</i> class may be subclassed to define a larger
- * level set.</p>
- *
- * @author VxR <vxr@vxr.it>
- * @version $Revision: 1.1 $
- * @package log4php
- * @since 0.5
- */
- class LoggerLevel {
- /**
- * @var integer
- */
- var $level;
-
- /**
- * @var string
- */
- var $levelStr;
-
- /**
- * @var integer
- */
- var $syslogEquivalent;
- /**
- * Constructor
- *
- * @param integer $level
- * @param string $levelStr
- * @param integer $syslogEquivalent
- */
- function LoggerLevel($level, $levelStr, $syslogEquivalent)
- {
- $this->level = $level;
- $this->levelStr = $levelStr;
- $this->syslogEquivalent = $syslogEquivalent;
- }
- /**
- * Two priorities are equal if their level fields are equal.
- *
- * @param object $o
- * @return boolean
- */
- function equals($o)
- {
- if (is_a($o, 'loggerlevel')) {
- return ($this->level == $o->level);
- } else {
- return false;
- }
- }
-
- /**
- * Returns an Off Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelOff()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_OFF_INT, 'OFF', 0);
- return $level;
- }
- /**
- * Returns a Fatal Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelFatal()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_FATAL_INT, 'FATAL', 0);
- return $level;
- }
-
- /**
- * Returns an Error Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelError()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ERROR_INT, 'ERROR', 3);
- return $level;
- }
-
- /**
- * Returns a Warn Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelWarn()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_WARN_INT, 'WARN', 4);
- return $level;
- }
- /**
- * Returns an Info Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelInfo()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_INFO_INT, 'INFO', 6);
- return $level;
- }
- /**
- * Returns a Debug Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelDebug()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_DEBUG_INT, 'DEBUG', 7);
- return $level;
- }
- /**
- * Returns an All Level
- * @static
- * @return LoggerLevel
- */
- function &getLevelAll()
- {
- static $level;
- if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ALL_INT, 'ALL', 7);
- return $level;
- }
-
- /**
- * Return the syslog equivalent of this priority as an integer.
- * @final
- * @return integer
- */
- function getSyslogEquivalent()
- {
- return $this->syslogEquivalent;
- }
- /**
- * Returns <i>true</i> if this level has a higher or equal
- * level than the level passed as argument, <i>false</i>
- * otherwise.
- *
- * <p>You should think twice before overriding the default
- * implementation of <i>isGreaterOrEqual</i> method.
- *
- * @param LoggerLevel $r
- * @return boolean
- */
- function isGreaterOrEqual($r)
- {
- return $this->level >= $r->level;
- }
- /**
- * Returns the string representation of this priority.
- * @return string
- * @final
- */
- function toString()
- {
- return $this->levelStr;
- }
- /**
- * Returns the integer representation of this level.
- * @return integer
- */
- function toInt()
- {
- return $this->level;
- }
- /**
- * Convert the string passed as argument to a level. If the
- * conversion fails, then this method returns a DEBUG Level.
- *
- * @param mixed $arg
- * @param LoggerLevel $default
- * @static
- */
- function &toLevel($arg, $defaultLevel = null)
- {
- if ($defaultLevel === null) {
- return LoggerLevel::toLevel($arg, LoggerLevel::getLevelDebug());
- } else {
- if (is_int($arg)) {
- switch($arg) {
- case LOG4PHP_LEVEL_ALL_INT: return LoggerLevel::getLevelAll();
- case LOG4PHP_LEVEL_DEBUG_INT: return LoggerLevel::getLevelDebug();
- case LOG4PHP_LEVEL_INFO_INT: return LoggerLevel::getLevelInfo();
- case LOG4PHP_LEVEL_WARN_INT: return LoggerLevel::getLevelWarn();
- case LOG4PHP_LEVEL_ERROR_INT: return LoggerLevel::getLevelError();
- case LOG4PHP_LEVEL_FATAL_INT: return LoggerLevel::getLevelFatal();
- case LOG4PHP_LEVEL_OFF_INT: return LoggerLevel::getLevelOff();
- default: return $defaultLevel;
- }
- } else {
- switch(strtoupper($arg)) {
- case 'ALL': return LoggerLevel::getLevelAll();
- case 'DEBUG': return LoggerLevel::getLevelDebug();
- case 'INFO': return LoggerLevel::getLevelInfo();
- case 'WARN': return LoggerLevel::getLevelWarn();
- case 'ERROR': return LoggerLevel::getLevelError();
- case 'FATAL': return LoggerLevel::getLevelFatal();
- case 'OFF': return LoggerLevel::getLevelOff();
- default: return $defaultLevel;
- }
- }
- }
- }
- }
- ?>
|