Index: branches/comu-ver2/data/class/logger/GC_Logger.php =================================================================== --- branches/comu-ver2/data/class/logger/GC_Logger.php (revision 18220) +++ branches/comu-ver2/data/class/logger/GC_Logger.php (revision 18220) @@ -0,0 +1,153 @@ +objLog = new GC_Log_Log4php($loggerName); + } + + /** + * インスタンスの取得 + * + * + * @param string logger名 + * @return GC_Logger GC_Loggerインスタンス + * + */ + function &gfGetInstance($loggerName='EC_CUBE') { + static $instances = array(); + + if(empty($loggerName)) { + $loggerName = 'EC_CUBE'; + } + + if(!array_key_exists($loggerName, $instances)) { + $instances[$loggerName] = new GC_Logger($loggerName); + } + + return $instances[$loggerName]; + } + + /** + * ログ整形 + * + * 文字列以外は、print_r形式に整形する + * + * @param mixed 出力したいログ + * @return mixed 整形されたログ + * + */ + function lfCastLog($obj) { + if(!is_string($obj)) { + ob_start(); + print_r($obj); + $obj = ob_get_contents(); + ob_end_clean(); + } + + return $obj; + } + + /** + * DEBUGログ + * + * @param string 出力したいログ + * @param mixed ダンプしたい変数 + * @return void + * + */ + function gfDebug($str, $dump='') { + $this->objLog->gfDebug($str . $this->lfCastLog($dump)); + } + + /** + * INFOログ + * + * @param string 出力したいログ + * @param mixed ダンプしたい変数 + * @return void + * + */ + function gfInfo($str, $dump='') { + $this->objLog->gfInfo($str . $this->lfCastLog($dump)); + } + + /** + * WARNログ + * + * @param string 出力したいログ + * @param mixed ダンプしたい変数 + * @return void + * + */ + function gfWarn($str, $dump='') { + $this->objLog->gfWarn($str . $this->lfCastLog($dump)); + } + + /** + * ERRORログ + * + * @param string 出力したいログ + * @param mixed ダンプしたい変数 + * @return void + * + */ + function gfError($str, $dump='') { + $this->objLog->gfError($str . $this->lfCastLog($dump)); + } + + /** + * FATALログ + * + * @param string 出力したいログ + * @param mixed ダンプしたい変数 + * @return void + * + */ + function gfFatal($str, $dump='') { + $this->objLog->gfFatal($str . $this->lfCastLog($dump)); + } +} +?> Index: branches/comu-ver2/data/class/logger/log/GC_Log_Log4php.php =================================================================== --- branches/comu-ver2/data/class/logger/log/GC_Log_Log4php.php (revision 18220) +++ branches/comu-ver2/data/class/logger/log/GC_Log_Log4php.php (revision 18220) @@ -0,0 +1,117 @@ += '5.0.0') { + require_once (realpath(dirname(__FILE__)) . '/../../../module/log4php/php5/log4php/LoggerManager.php'); +} else { + require_once (realpath(dirname(__FILE__)) . '/../../../module/log4php/php4/log4php/LoggerManager.php'); +} + +require_once (realpath(dirname(__FILE__)) . '/GC_Log_Interface.php'); + +/** + * GC_Log_Log4phpクラス + * + * ロギングをlog4phpで行うクラス + * + * + * @package Logger + * @author LOCKON CO.,LTD. + * @version $Id$ + */ + +class GC_Log_Log4php extends GC_Log_Interface{ + /** @var logger loggerインスタンス*/ + var $logger; + + /** + * コンストラクタ + * + * @param void + * @return void + * + */ + function GC_Log_Log4php($loggerName='EC_CUBE') { + $this->logger =& LoggerManager::getLogger($loggerName); + } + + /** + * DEBUGログ + * + * @param string 出力したいログ + * @return void + * + */ + function gfDebug($log) { + $this->logger->debug($log); + } + + /** + * INFOログ + * + * @param string 出力したいログ + * @return void + * + */ + function gfInfo($log) { + $this->logger->info($log); + } + + /** + * WARNログ + * + * @param string 出力したいログ + * @return void + * + */ + function gfWarn($log) { + $this->logger->warn($log); + } + + /** + * ERRORログ + * + * @param string 出力したいログ + * @return void + * + */ + function gfError($log) { + $this->logger->error($log); + } + + /** + * FATALログ + * + * @param string 出力したいログ + * @return void + * + */ + function gfFatal($log) { + $this->logger->fatal($log); + } +} +?> Index: branches/comu-ver2/data/class/logger/log/GC_Log_Interface.php =================================================================== --- branches/comu-ver2/data/class/logger/log/GC_Log_Interface.php (revision 18220) +++ branches/comu-ver2/data/class/logger/log/GC_Log_Interface.php (revision 18220) @@ -0,0 +1,90 @@ + Index: branches/comu-ver2/data/conf/log4php.properties =================================================================== --- branches/comu-ver2/data/conf/log4php.properties (revision 18220) +++ branches/comu-ver2/data/conf/log4php.properties (revision 18220) @@ -0,0 +1,25 @@ +#--------------------------------- +# @rotete daily +# @logfile /var/tmp/eccube_%s.log +# @pattern %d [%t] %-5p %c - %m%n +#--------------------------------- +log4php.rootLogger=DEBUG, R01, R02 +log4php.appender.R01=LoggerAppenderDailyFile +log4php.appender.R01.file=/var/tmp/eccube_%s.log +log4php.appender.R01.layout=LoggerPatternLayout +log4php.appender.R01.layout.ConversionPattern="%d [%p] %m%n" + +#--------------------------------- +# @rotete mail +# @from sample@example.com +# @to sample@example.com +# @subject 'EC-CUBE SYSTEM ERROR' +# @threshold ERROR +#--------------------------------- +log4php.appender.R02=LoggerAppenderMailEvent +log4php.appender.R02.layout=LoggerPatternLayout +log4php.appender.R02.layout.ConversionPattern="%d [%p] %m%n" +log4php.appender.R02.from=sample@example.com +;log4php.appender.R02.to=sample@example.com +log4php.appender.R02.subject="EC-CUBE SYSTEM ERROR" +log4php.appender.R02.threshold=ERROR Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerRoot.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerRoot.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerRoot.php (revision 18220) @@ -0,0 +1,105 @@ +name); + if ($level == null) + $level = LoggerLevel::getLevelAll(); + $this->setLevel($level); + } + + /** + * @return LoggerLevel the level + */ + public function getChainedLevel() + { + return $this->level; + } + + /** + * Setting a null value to the level of the root category may have catastrophic results. + * @param LoggerLevel $level + */ + public function setLevel($level) + { + if ($level != null) { + $this->level = $level; + } + } + + /** + * Please use setLevel() instead. + * @param LoggerLevel $level + * @deprecated + */ + public function setPriority($level) + { + $this->setLevel($level); + } + + /** + * Always returns false. + * Because LoggerRoot has no parents, it returns false. + * @param Logger $parent + * @return boolean + */ + public function setParent($parent) + { + return false; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerRendererMap.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerRendererMap.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerRendererMap.php (revision 18220) @@ -0,0 +1,186 @@ +map = array(); + $this->defaultRenderer = new LoggerDefaultRenderer(); + } + + /** + * Add a renderer to a hierarchy passed as parameter. + * Note that hierarchy must implement getRendererMap() and setRenderer() methods. + * + * @param LoggerHierarchy $repository a logger repository. + * @param string $renderedClassName + * @param string $renderingClassName + * @static + */ + public static function addRenderer($repository, $renderedClassName, $renderingClassName) + { + LoggerLog::debug("LoggerRendererMap::addRenderer() Rendering class: [{$renderingClassName}], Rendered class: [{$renderedClassName}]."); + $renderer = LoggerObjectRenderer::factory($renderingClassName); + if($renderer == null) { + LoggerLog::warn("LoggerRendererMap::addRenderer() Could not instantiate renderer [{$renderingClassName}]."); + return; + } else { + $repository->setRenderer($renderedClassName, $renderer); + } + } + + + /** + * Find the appropriate renderer for the class type of the + * o parameter. + * + * This is accomplished by calling the {@link getByObject()} + * method if o is object or using {@link LoggerDefaultRenderer}. + * Once a renderer is found, it is applied on the object o and + * the result is returned as a string. + * + * @param mixed $o + * @return string + */ + public function findAndRender($o) + { + if($o == null) { + return null; + } else { + if (is_object($o)) { + $renderer = $this->getByObject($o); + if ($renderer !== null) { + return $renderer->doRender($o); + } else { + return null; + } + } else { + $renderer = $this->defaultRenderer; + return $renderer->doRender($o); + } + } + } + + /** + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the + * class of the object parameter. + * + * @param mixed $o + * @return string + */ + public function getByObject($o) + { + return ($o == null) ? null : $this->getByClassName(get_class($o)); + } + + + /** + * Search the parents of clazz for a renderer. + * + * The renderer closest in the hierarchy will be returned. If no + * renderers could be found, then the default renderer is returned. + * + * @param string $class + * @return LoggerObjectRenderer + */ + public function getByClassName($class) + { + $r = null; + for($c = strtolower($class); !empty($c); $c = get_parent_class($c)) { + if (isset($this->map[$c])) { + return $this->map[$c]; + } + } + return $this->defaultRenderer; + } + + /** + * @return LoggerDefaultRenderer + */ + public function getDefaultRenderer() + { + return $this->defaultRenderer; + } + + + public function clear() + { + $this->map = array(); + } + + /** + * Register a {@link LoggerObjectRenderer} for clazz. + * @param string $class + * @param LoggerObjectRenderer $or + */ + public function put($class, $or) + { + $this->map[strtolower($class)] = $or; + } + + /** + * @param string $class + * @return boolean + */ + public function rendererExists($class) + { + $class = basename($class); + if (!class_exists($class)) { + include_once(LOG4PHP_DIR ."/or/{$class}.php"); + } + return class_exists($class); + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerDefaultRenderer.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerDefaultRenderer.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/or/LoggerDefaultRenderer.php (revision 18220) @@ -0,0 +1,51 @@ +Parameters are + * {@link $smtpHost} (optional), + * {@link $port} (optional), + * {@link $from} (optional), + * {@link $to}, + * {@link $subject} (optional).
+ *A layout is required.
+ * + * @author Domenico LordiParameters are {@link $dsn}, {@link $createTable}, {@link table} and {@link $sql}.
+ *See examples in test directory.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage appenders + * @since 0.3 + */ +class LoggerAppenderDb extends LoggerAppenderSkeleton { + + /** + * Create the log table if it does not exists (optional). + * @var boolean + */ + var $createTable = true; + + /** + * PEAR::Db Data source name. Read PEAR::Db for dsn syntax (mandatory). + * @var string + */ + var $dsn; + + /** + * A {@link LoggerPatternLayout} string used to format a valid insert query (mandatory). + * @var string + */ + var $sql; + + /** + * Table name to write events. Used only if {@link $createTable} is true. + * @var string + */ + var $table; + + /** + * @var object PEAR::Db instance + * @access private + */ + var $db = null; + + /** + * @var boolean used to check if all conditions to append are true + * @access private + */ + var $canAppend = true; + + /** + * @access private + */ + var $requiresLayout = false; + + /** + * Constructor. + * + * @param string $name appender name + */ + function LoggerAppenderDb($name) + { + $this->LoggerAppenderSkeleton($name); + } + + /** + * Setup db connection. + * Based on defined options, this method connects to db defined in {@link $dsn} + * and creates a {@link $table} table if {@link $createTable} is true. + * @return boolean true if all ok. + */ + function activateOptions() + { + $this->db = DB::connect($this->dsn); + + if (DB::isError($this->db)) { + LoggerLog::debug("LoggerAppenderDb::activateOptions() DB Connect Error [".$this->db->getMessage()."]"); + $this->db = null; + $this->closed = true; + $this->canAppend = false; + + } else { + + $this->layout = LoggerLayout::factory('LoggerPatternLayout'); + $this->layout->setConversionPattern($this->getSql()); + + // test if log table exists + $tableInfo = $this->db->tableInfo($this->table, $mode = null); + if (DB::isError($tableInfo) and $this->getCreateTable()) { + $query = "CREATE TABLE {$this->table} (timestamp varchar(32),logger varchar(32),level varchar(32),message varchar(64),thread varchar(32),file varchar(64),line varchar(4) );"; + + LoggerLog::debug("LoggerAppenderDb::activateOptions() creating table '{$this->table}'... using sql='$query'"); + + $result = $this->db->query($query); + if (DB::isError($result)) { + LoggerLog::debug("LoggerAppenderDb::activateOptions() error while creating '{$this->table}'. Error is ".$result->getMessage()); + $this->closed = true; + $this->canAppend = false; + return; + } + } + $this->canAppend = true; + $this->closed = false; + } + + } + + function append($event) + { + if ($this->canAppend) { + + $query = $this->layout->format($event); + + LoggerLog::debug("LoggerAppenderDb::append() query='$query'"); + + $this->db->query($query); + } + } + + function close() + { + if ($this->db !== null) + $this->db->disconnect(); + $this->closed = true; + } + + /** + * @return boolean + */ + function getCreateTable() + { + return $this->createTable; + } + + /** + * @return string the defined dsn + */ + function getDsn() + { + return $this->dsn; + } + + /** + * @return string the sql pattern string + */ + function getSql() + { + return $this->sql; + } + + /** + * @return string the table name to create + */ + function getTable() + { + return $this->table; + } + + function setCreateTable($flag) + { + $this->createTable = LoggerOptionConverter::toBoolean($flag, true); + } + + function setDsn($newDsn) + { + $this->dsn = $newDsn; + } + + function setSql($sql) + { + $this->sql = $sql; + } + + function setTable($table) + { + $this->table = $table; + } + +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderRollingFile.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderRollingFile.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderRollingFile.php (revision 18220) @@ -0,0 +1,240 @@ +Parameters are {@link $maxFileSize}, {@link $maxBackupIndex}. + * + *Contributors: Sergio Strampelli.
+ * + * @author Marco Vassura + * @version $Revision: 640254 $ + * @package log4php + * @subpackage appenders + */ +class LoggerAppenderRollingFile extends LoggerAppenderFile { + + /** + * Set the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + * + *In configuration files, the MaxFileSize option takes a + * long integer in the range 0 - 2^63. You can specify the value + * with the suffixes "KB", "MB" or "GB" so that the integer is + * interpreted being expressed respectively in kilobytes, megabytes + * or gigabytes. For example, the value "10KB" will be interpreted + * as 10240.
+ *The default maximum file size is 10MB.
+ * + *Note that MaxFileSize cannot exceed 2 GB.
+ * + * @var integer + */ + var $maxFileSize = 10485760; + + /** + * Set the maximum number of backup files to keep around. + * + *The MaxBackupIndex option determines how many backup + * files are kept before the oldest is erased. This option takes + * a positive integer value. If set to zero, then there will be no + * backup files and the log file will be truncated when it reaches + * MaxFileSize.
+ *There is one backup file by default.
+ * + * @var integer + */ + var $maxBackupIndex = 1; + + /** + * @var string the filename expanded + * @access private + */ + var $expandedFileName = null; + + /** + * Constructor. + * + * @param string $name appender name + */ + public function __construct($name) { + parent::__construct($name); + } + + /** + * Returns the value of the MaxBackupIndex option. + * @return integer + */ + function getExpandedFileName() { + return $this->expandedFileName; + } + + /** + * Returns the value of the MaxBackupIndex option. + * @return integer + */ + function getMaxBackupIndex() { + return $this->maxBackupIndex; + } + + /** + * Get the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + * @return integer + */ + function getMaximumFileSize() { + return $this->maxFileSize; + } + + /** + * Implements the usual roll over behaviour. + * + *If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. + * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. + * + *
If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. + */ + function rollOver() + { + // If maxBackups <= 0, then there is no file renaming to be done. + if($this->maxBackupIndex > 0) { + $fileName = $this->getExpandedFileName(); + // Delete the oldest file, to keep Windows happy. + $file = $fileName . '.' . $this->maxBackupIndex; + if (is_writable($file)) + unlink($file); + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} + for ($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { + $file = $fileName . "." . $i; + if (is_readable($file)) { + $target = $fileName . '.' . ($i + 1); + rename($file, $target); + } + } + + // Rename fileName to fileName.1 + $target = $fileName . ".1"; + + $this->closeFile(); // keep windows happy. + + $file = $fileName; + rename($file, $target); + } + + $this->setFile($fileName, false); + unset($this->fp); + $this->activateOptions(); + } + + function setFileName($fileName) + { + $this->fileName = $fileName; + $this->expandedFileName = realpath($fileName); + LoggerLog::debug("LoggerAppenderRollingFile::setFileName():filename=[{$fileName}]:expandedFileName=[{$this->expandedFileName}]"); + } + + + /** + * Set the maximum number of backup files to keep around. + * + *
The MaxBackupIndex option determines how many backup + * files are kept before the oldest is erased. This option takes + * a positive integer value. If set to zero, then there will be no + * backup files and the log file will be truncated when it reaches + * MaxFileSize. + * + * @param mixed $maxBackups + */ + function setMaxBackupIndex($maxBackups) + { + if (is_numeric($maxBackups)) + $this->maxBackupIndex = abs((int)$maxBackups); + } + + /** + * Set the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + * + * @param mixed $maxFileSize + * @see setMaxFileSize() + */ + function setMaximumFileSize($maxFileSize) + { + $this->setMaxFileSize($maxFileSize); + } + + /** + * Set the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + *
In configuration files, the MaxFileSize option takes an + * long integer in the range 0 - 2^63. You can specify the value + * with the suffixes "KB", "MB" or "GB" so that the integer is + * interpreted being expressed respectively in kilobytes, megabytes + * or gigabytes. For example, the value "10KB" will be interpreted + * as 10240. + * + * @param mixed $value + */ + function setMaxFileSize($value) + { + $maxFileSize = null; + $numpart = substr($value,0, strlen($value) -2); + $suffix = strtoupper(substr($value, -2)); + + switch ($suffix) { + case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; + case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; + case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; + default: + if (is_numeric($value)) { + $maxFileSize = (int)$value; + } + } + + if ($maxFileSize === null) { + LoggerLog::debug("LoggerAppenderRollingFile::setMaxFileSize():value=[$value] wrong declaration"); + } else { + $this->maxFileSize = abs($maxFileSize); + } + } + + /** + * @param LoggerLoggingEvent $event + */ + function append($event) + { + if ($this->fp) { + parent::append($event); + if (ftell($this->fp) > $this->getMaximumFileSize()) + $this->rollOver(); + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderPhp.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderPhp.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderPhp.php (revision 18220) @@ -0,0 +1,70 @@ +Levels are mapped as follows:
+ * - level < WARN mapped to E_USER_NOTICE + * - WARN <= level < ERROR mapped to E_USER_WARNING + * - level >= ERROR mapped to E_USER_ERROR + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage appenders + */ +class LoggerAppenderPhp extends LoggerAppenderSkeleton { + + + public function activateOptions() { + $this->layout = LoggerLayout::factory('LoggerLayoutTTCC'); + $this->closed = false; + } + + public function close() { + $this->closed = true; + } + + public function append($event) { + if ($this->layout !== null) { + LoggerLog::debug("LoggerAppenderPhp::append()"); + $level = $event->getLevel(); + if ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) { + trigger_error($this->layout->format($event), E_USER_ERROR); + } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) { + trigger_error($this->layout->format($event), E_USER_WARNING); + } else { + trigger_error($this->layout->format($event), E_USER_NOTICE); + } + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderSocket.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderSocket.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderSocket.php (revision 18220) @@ -0,0 +1,245 @@ +false. + */ + var $log4jNamespace = false; + + /** + * @var LoggerXmlLayout + * @access private + */ + var $xmlLayout = null; + + /** + * Create a socket connection using defined parameters + */ + public function activateOptions() { + LoggerLog::debug("LoggerAppenderSocket::activateOptions() creating a socket..."); + $errno = 0; + $errstr = ''; + $this->sp = @fsockopen($this->getRemoteHost(), $this->getPort(), $errno, $errstr, $this->getTimeout()); + if ($errno) { + LoggerLog::debug("LoggerAppenderSocket::activateOptions() socket error [$errno] $errstr"); + $this->closed = true; + } else { + LoggerLog::debug("LoggerAppenderSocket::activateOptions() socket created [".$this->sp."]"); + if ($this->getUseXml()) { + $this->xmlLayout = LoggerLayout::factory('LoggerXmlLayout'); + if ($this->xmlLayout === null) { + LoggerLog::debug("LoggerAppenderSocket::activateOptions() useXml is true but layout is null"); + $this->setUseXml(false); + } else { + $this->xmlLayout->setLocationInfo($this->getLocationInfo()); + $this->xmlLayout->setLog4jNamespace($this->getLog4jNamespace()); + $this->xmlLayout->activateOptions(); + } + } + $this->closed = false; + } + } + + public function close() { + fclose($this->sp); + $this->closed = true; + } + + /** + * @return string + */ + public function getHostname() { + return $this->getRemoteHost(); + } + + /** + * @return boolean + */ + public function getLocationInfo() { + return $this->locationInfo; + } + + /** + * @return boolean + */ + public function getLog4jNamespace() { + return $this->log4jNamespace; + } + + /** + * @return integer + */ + public function getPort() { + return $this->port; + } + + public function getRemoteHost() { + return $this->remoteHost; + } + + /** + * @return integer + */ + public function getTimeout() { + return $this->timeout; + } + + /** + * @var boolean + */ + public function getUseXml() { + return $this->useXml; + } + + public function reset() { + $this->close(); + parent::reset(); + } + + /** + * @param mixed + */ + public function setLocationInfo($flag) { + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo()); + } + + /** + * @param mixed + */ + public function setLog4jNamespace($flag) { + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace()); + } + + /** + * @param integer + */ + public function setPort($port) { + $port = LoggerOptionConverter::toInt($port, 0); + if ($port > 0 and $port < 65535) + $this->port = $port; + } + + /** + * @param string + */ + public function setRemoteHost($hostname) { + $this->remoteHost = $hostname; + } + + /** + * @param integer + */ + public function setTimeout($timeout) { + $this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout()); + } + + /** + * @param mixed + */ + public function setUseXml($flag) { + $this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml()); + } + + /** + * @param LoggerLoggingEvent + */ + public function append($event) { + if ($this->sp) { + + LoggerLog::debug("LoggerAppenderSocket::append()"); + + if ($this->getLocationInfo()) + $event->getLocationInformation(); + + if (!$this->getUseXml()) { + $sEvent = serialize($event); + fwrite($this->sp, $sEvent, strlen($sEvent)); + } else { + fwrite($this->sp, $this->xmlLayout->format($event)); + } + + // not sure about it... + fflush($this->sp); + } + } +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderAdodb.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderAdodb.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/appenders/LoggerAppenderAdodb.php (revision 18220) @@ -0,0 +1,281 @@ +This appender uses a table in a database to log events. + *Parameters are {@link $host}, {@link $user}, {@link $password}, + * {@link $database}, {@link $createTable}, {@link $table} and {@link $sql}.
+ *See examples in test directory.
+ * + * @author sbwNote: Use this Appender with command-line php scripts. + * On web scripts this appender has no effects.
+ *This appender requires a layout.
+ * + * @author Marco Vassura + * @author Knut UrdalenThis appender requires a layout.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage appenders + */ +class LoggerAppenderMail extends LoggerAppenderSkeleton { + + /** + * @var string 'from' field + */ + var $from = null; + + /** + * @var string 'subject' field + */ + var $subject = 'Log4php Report'; + + /** + * @var string 'to' field + */ + var $to = null; + + /** + * @var string used to create mail body + * @access private + */ + var $body = ''; + + /** + * Constructor. + * + * @param string $name appender name + */ + public function __construct($name) { + parent::__construct($name); + $this->requiresLayout = true; + } + + public function activateOptions() { + $this->closed = false; + } + + public function close() { + $from = $this->from; + $to = $this->to; + + if (!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) { + $subject = $this->subject; + LoggerLog::debug("LoggerAppenderMail::close() sending mail from=[{$from}] to=[{$to}] subject=[{$subject}]"); + mail( + $to, $subject, + $this->layout->getHeader() . $this->body . $this->layout->getFooter(), + "From: {$from}\r\n" + ); + } + $this->closed = true; + } + + /** + * @return string + */ + function getFrom() + { + return $this->from; + } + + /** + * @return string + */ + function getSubject() + { + return $this->subject; + } + + /** + * @return string + */ + function getTo() + { + return $this->to; + } + + function setSubject($subject) + { + $this->subject = $subject; + } + + function setTo($to) + { + $this->to = $to; + } + + function setFrom($from) + { + $this->from = $from; + } + + function append($event) + { + if ($this->layout !== null) + $this->body .= $this->layout->format($event); + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppender.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppender.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppender.php (revision 18220) @@ -0,0 +1,184 @@ +null if no is filter is set. + * @return LoggerFilter + */ + abstract function getFilter(); + + /** + * Release any resources allocated. + * Subclasses of {@link LoggerAppender} should implement + * this method to perform proper closing procedures. + * @abstract + */ + abstract public function close(); + + /** + * This method performs threshold checks and invokes filters before + * delegating actual logging to the subclasses specific append() method. + * @param LoggerLoggingEvent $event + * @abstract + */ + abstract public function doAppend($event); + + /** + * Get the name of this appender. + * @return string + */ + abstract public function getName(); + + /** + * Do not use this method. + * + * @param object $errorHandler + */ + abstract public function setErrorHandler($errorHandler); + + /** + * Do not use this method. + * @return object Returns the ErrorHandler for this appender. + */ + abstract public function getErrorHandler(); + + /** + * Set the Layout for this appender. + * + * @param LoggerLayout $layout + */ + abstract public function setLayout($layout); + + /** + * Returns this appender layout. + * @return LoggerLayout + */ + abstract public function getLayout(); + + /** + * Set the name of this appender. + * + * The name is used by other components to identify this appender. + * + * @param string $name + */ + abstract public function setName($name); + + /** + * Configurators call this method to determine if the appender + * requires a layout. + * + *If this method returns true, meaning that layout is required, + * then the configurator will configure a layout using the configuration + * information at its disposal. If this method returns false, + * meaning that a layout is not required, then layout configuration will be + * skipped even if there is available layout configuration + * information at the disposal of the configurator.
+ * + *In the rather exceptional case, where the appender + * implementation admits a layout but can also work without it, then + * the appender should return true.
+ * + * @return boolean + */ + abstract public function requiresLayout(); + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppenderSkeleton.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppenderSkeleton.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerAppenderSkeleton.php (revision 18220) @@ -0,0 +1,337 @@ +name = $name; + $this->clearFilters(); + } + + /** + * @param LoggerFilter $newFilter add a new LoggerFilter + * @see LoggerAppender::addFilter() + */ + public function addFilter($newFilter) { + if($this->headFilter === null) { + $this->headFilter = $newFilter; + $this->tailFilter = $this->headFilter; + } else { + $this->tailFilter->next = $newFilter; + $this->tailFilter = $this->tailFilter->next; + } + } + + /** + * Derived appenders should override this method if option structure + * requires it. + */ + abstract public function activateOptions(); + + /** + * Subclasses of {@link LoggerAppenderSkeleton} should implement + * this method to perform actual logging. + * + * @param LoggerLoggingEvent $event + * @see doAppend() + * @abstract + */ + abstract protected function append($event); + + /** + * @see LoggerAppender::clearFilters() + */ + public function clearFilters() + { + unset($this->headFilter); + unset($this->tailFilter); + $this->headFilter = null; + $this->tailFilter = null; + } + + /** + * Finalize this appender by calling the derived class' close() method. + */ + public function finalize() + { + // An appender might be closed then garbage collected. There is no + // point in closing twice. + if ($this->closed) return; + + LoggerLog::debug("LoggerAppenderSkeleton::finalize():name=[{$this->name}]."); + + $this->close(); + } + + /** + * Do not use this method. + * @see LoggerAppender::getErrorHandler() + * @return object + */ + public function getErrorHandler() + { + return $this->errorHandler; + } + + /** + * @see LoggerAppender::getFilter() + * @return LoggerFilter + */ + public function getFilter() + { + return $this->headFilter; + } + + /** + * Return the first filter in the filter chain for this Appender. + * The return value may be null if no is filter is set. + * @return LoggerFilter + */ + public function getFirstFilter() + { + return $this->headFilter; + } + + /** + * @see LoggerAppender::getLayout() + * @return LoggerLayout + */ + public function getLayout() + { + return $this->layout; + } + + /** + * @see LoggerAppender::getName() + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Returns this appenders threshold level. + * See the {@link setThreshold()} method for the meaning of this option. + * @return LoggerLevel + */ + public function getThreshold() + { + return $this->threshold; + } + + /** + * Check whether the message level is below the appender's threshold. + * + * + * If there is no threshold set, then the return value is always true. + * @param LoggerLevel $priority + * @return boolean true if priority is greater or equal than threshold + */ + public function isAsSevereAsThreshold($priority) + { + if ($this->threshold === null) + return true; + + return $priority->isGreaterOrEqual($this->getThreshold()); + } + + /** + * @see LoggerAppender::doAppend() + * @param LoggerLoggingEvent $event + */ + public function doAppend($event) + { + LoggerLog::debug("LoggerAppenderSkeleton::doAppend()"); + + if ($this->closed) { + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() Attempted to append to closed appender named [{$this->name}]."); + return; + } + if(!$this->isAsSevereAsThreshold($event->getLevel())) { + LoggerLog::debug("LoggerAppenderSkeleton::doAppend() event level is less severe than threshold."); + return; + } + + $f = $this->getFirstFilter(); + + while($f !== null) { + switch ($f->decide($event)) { + case LOG4PHP_LOGGER_FILTER_DENY: return; + case LOG4PHP_LOGGER_FILTER_ACCEPT: return $this->append($event); + case LOG4PHP_LOGGER_FILTER_NEUTRAL: $f = $f->getNext(); + } + } + $this->append($event); + } + + + /** + * @see LoggerAppender::requiresLayout() + * @return boolean + */ + public function requiresLayout() + { + return $this->requiresLayout; + } + + /** + * @see LoggerAppender::setErrorHandler() + * @param object + */ + public function setErrorHandler($errorHandler) + { + if($errorHandler == null) { + // We do not throw exception here since the cause is probably a + // bad config file. + LoggerLog::warn("You have tried to set a null error-handler."); + } else { + $this->errorHandler = $errorHandler; + } + } + + /** + * @see LoggerAppender::setLayout() + * @param LoggerLayout $layout + */ + public function setLayout($layout) + { + if ($this->requiresLayout()) + $this->layout = $layout; + } + + /** + * @see LoggerAppender::setName() + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Set the threshold level of this appender. + * + * @param mixed $threshold can be a {@link LoggerLevel} object or a string. + * @see LoggerOptionConverter::toLevel() + */ + public function setThreshold($threshold) + { + if (is_string($threshold)) { + $this->threshold = LoggerOptionConverter::toLevel($threshold, null); + }elseif ($threshold instanceof LoggerLevel) { + $this->threshold = $threshold; + } + } + + /** + * Perform actions before object serialization. + * + * Call {@link finalize()} to properly close the appender. + */ + function __sleep() + { + $this->finalize(); + return array_keys(get_object_vars($this)); + } + + /** + * Perform actions after object de-serialization. + * + * Call {@link activateOptions()} to properly setup the appender. + */ + function __wakeup() + { + $this->activateOptions(); + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerMDC.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerMDC.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerMDC.php (revision 18220) @@ -0,0 +1,131 @@ +mapped diagnostic contexts. + * + * A Mapped Diagnostic Context, or + * MDC in short, is an instrument for distinguishing interleaved log + * output from different sources. Log output is typically interleaved + * when a server handles multiple clients near-simultaneously. + * + *The MDC is managed on a per thread basis. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @since 0.3 + * @package log4php + */ +class LoggerMDC { + + /** + * Put a context value as identified with the key parameter into the current thread's + * context map. + * + *
If the current thread does not have a context map it is + * created as a side effect.
+ * + *Note that you cannot put more than {@link LOGGER_MDC_HT_SIZE} keys.
+ * + * @param string $key the key + * @param string $value the value + * @static + */ + public static function put($key, $value) + { + if ( sizeof($GLOBALS['log4php.LoggerMDC.ht']) < LOGGER_MDC_HT_SIZE ) + $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value; + } + + /** + * Get the context identified by the key parameter. + * + *You can use special key identifiers to map values in + * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.' + * followed by the var name you want to refer.
+ * + *This method has no side effects.
+ * + * @param string $key + * @return string + * @static + */ + public static function get($key) + { + LoggerLog::debug("LoggerMDC::get() key='$key'"); + + if (!empty($key)) { + if (strpos($key, 'server.') === 0) { + $varName = substr($key, 7); + + LoggerLog::debug("LoggerMDC::get() a _SERVER[$varName] is requested."); + + return @$_SERVER[$varName]; + } elseif (strpos($key, 'env.') === 0) { + + $varName = substr($key, 4); + + LoggerLog::debug("LoggerMDC::get() a _ENV[$varName] is requested."); + + return @$_ENV[$varName]; + } elseif (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) { + + LoggerLog::debug("LoggerMDC::get() a user key is requested."); + + return $GLOBALS['log4php.LoggerMDC.ht'][$key]; + } + } + return ''; + } + + /** + * Remove the the context identified by the key parameter. + * + * It only affects user mappings. + * + * @param string $key + * @return string + * @static + */ + public static function remove($key) + { + unset($GLOBALS['log4php.LoggerMDC.ht'][$key]); + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerBasicConfigurator.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerBasicConfigurator.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerBasicConfigurator.php (revision 18220) @@ -0,0 +1,72 @@ +For file based configuration see {@link LoggerPropertyConfigurator}. + *For XML based configuration see {@link LoggerDOMConfigurator}.
+ *
+ * @author Marco Vassura
+ * @version $Revision: 635069 $
+ * @package log4php
+ */
+class LoggerBasicConfigurator implements LoggerConfigurator {
+
+ /**
+ * Add a {@link LoggerAppenderConsole} that uses
+ * the {@link LoggerLayoutTTCC} to the root category.
+ *
+ * @param string $url not used here
+ */
+ public static function configure($url = null)
+ {
+ $root = LoggerManager::getRootLogger();
+ $appender = new LoggerAppenderConsole('A1');
+ $appender->setLayout( new LoggerLayoutTTCC() );
+ $root->addAppender($appender);
+ }
+
+ /**
+ * Reset the default hierarchy to its default.
+ * It is equivalent to
+ *
+ * LoggerManager::resetConfiguration();
+ *
+ *
+ * @see LoggerHierarchy::resetConfiguration()
+ * @static
+ */
+ public static function resetConfiguration()
+ {
+ LoggerManager::resetConfiguration();
+ }
+}
Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerNDC.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerNDC.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerNDC.php (revision 18220)
@@ -0,0 +1,242 @@
+nested diagnostic contexts as
+ * defined by Neil Harrison in the article "Patterns for Logging
+ * Diagnostic Messages" part of the book "Pattern Languages of
+ * Program Design 3" edited by Martin et al.
+ *
+ *
A Nested Diagnostic Context, or NDC in short, is an instrument + * to distinguish interleaved log output from different sources. Log + * output is typically interleaved when a server handles multiple + * clients near-simultaneously. + * + *
Interleaved log output can still be meaningful if each log entry + * from different contexts had a distinctive stamp. This is where NDCs + * come into play. + * + *
Note that NDCs are managed on a per thread + * basis. NDC operations such as {@link push()}, {@link pop()}, + * {@link clear()}, {@link getDepth()} and {@link setMaxDepth()} + * affect the NDC of the current thread only. NDCs of other + * threads remain unaffected. + * + *
For example, a servlet can build a per client request NDC + * consisting the clients host name and other information contained in + * the the request. Cookies are another source of distinctive + * information. To build an NDC one uses the {@link push()} + * operation.
+ * + * Simply put, + * + * - Contexts can be nested. + * - When entering a context, call + *LoggerNDC::push()
+ * As a side effect, if there is no nested diagnostic context for the
+ * current thread, this method will create it.
+ * - When leaving a context, call
+ * LoggerNDC::pop()
+ * - When exiting a thread make sure to call {@link remove()}
+ *
+ * There is no penalty for forgetting to match each
+ * push
operation with a corresponding pop
,
+ * except the obvious mismatch between the real application context
+ * and the context set in the NDC.
If configured to do so, {@link LoggerPatternLayout} and {@link LoggerLayoutTTCC} + * instances automatically retrieve the nested diagnostic + * context for the current thread without any user intervention. + * Hence, even if a servlet is serving multiple clients + * simultaneously, the logs emanating from the same code (belonging to + * the same category) can still be distinguished because each client + * request will have a different NDC tag.
+ * + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @since 0.3 + */ +class LoggerNDC { + + /** + * Clear any nested diagnostic information if any. This method is + * useful in cases where the same thread can be potentially used + * over and over in different unrelated contexts. + * + *This method is equivalent to calling the {@link setMaxDepth()} + * method with a zero maxDepth argument. + * + * @static + */ + public static function clear() + { + LoggerLog::debug("LoggerNDC::clear()"); + + $GLOBALS['log4php.LoggerNDC.ht'] = array(); + } + + /** + * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. + * @static + * @return array + */ + public static function get() + { + LoggerLog::debug("LoggerNDC::get()"); + + return $GLOBALS['log4php.LoggerNDC.ht']; + } + + /** + * Get the current nesting depth of this diagnostic context. + * + * @see setMaxDepth() + * @return integer + * @static + */ + public static function getDepth() + { + LoggerLog::debug("LoggerNDC::getDepth()"); + + return sizeof($GLOBALS['log4php.LoggerNDC.ht']); + } + + /** + * Clients should call this method before leaving a diagnostic + * context. + * + *
The returned value is the value that was pushed last. If no + * context is available, then the empty string "" is returned.
+ * + * @return string The innermost diagnostic context. + * @static + */ + public static function pop() + { + LoggerLog::debug("LoggerNDC::pop()"); + + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) { + return array_pop($GLOBALS['log4php.LoggerNDC.ht']); + } else { + return ''; + } + } + + /** + * Looks at the last diagnostic context at the top of this NDC + * without removing it. + * + *The returned value is the value that was pushed last. If no + * context is available, then the empty string "" is returned.
+ * @return string The innermost diagnostic context. + * @static + */ + public static function peek() + { + LoggerLog::debug("LoggerNDC::peek()"); + + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) { + return end($GLOBALS['log4php.LoggerNDC.ht']); + } else { + return ''; + } + } + + /** + * Push new diagnostic context information for the current thread. + * + *The contents of the message parameter is + * determined solely by the client. + * + * @param string $message The new diagnostic context information. + * @static + */ + public static function push($message) + { + LoggerLog::debug("LoggerNDC::push()"); + + array_push($GLOBALS['log4php.LoggerNDC.ht'], (string)$message); + } + + /** + * Remove the diagnostic context for this thread. + * @static + */ + public static function remove() + { + LoggerLog::debug("LoggerNDC::remove()"); + + LoggerNDC::clear(); + } + + /** + * Set maximum depth of this diagnostic context. If the current + * depth is smaller or equal to maxDepth, then no + * action is taken. + * + *
This method is a convenient alternative to multiple + * {@link pop()} calls. Moreover, it is often the case that at + * the end of complex call sequences, the depth of the NDC is + * unpredictable. The {@link setMaxDepth()} method circumvents + * this problem. + * + * @param integer $maxDepth + * @see getDepth() + * @static + */ + public static function setMaxDepth($maxDepth) + { + LoggerLog::debug("LoggerNDC::setMaxDepth() maxDepth='$maxDepth'"); + + $maxDepth = (int)$maxDepth; + if ($maxDepth <= LOGGER_NDC_HT_SIZE) { + if (LoggerNDC::getDepth() > $maxDepth) { + $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth); + } + $GLOBALS['log4php.LoggerNDC.maxDepth'] = $maxDepth; + } + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFactory.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFactory.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFactory.php (revision 18220) @@ -0,0 +1,50 @@ + This field should not be accessed directly. You shoud use the + * {@link getLevel()} method instead. + * + * @deprecated + * @var LoggerLevel + */ + protected $level; + + /** + * @var string The nested diagnostic context (NDC) of logging event. + */ + var $ndc; + + /** + * Have we tried to do an NDC lookup? If we did, there is no need + * to do it again. Note that its value is always false when + * serialized. Thus, a receiving SocketNode will never use it's own + * (incorrect) NDC. See also writeObject method. + * @var boolean + */ + var $ndcLookupRequired = true; + + /** + * Have we tried to do an MDC lookup? If we did, there is no need + * to do it again. Note that its value is always false when + * serialized. See also the getMDC and getMDCCopy methods. + * @var boolean + */ + var $mdcCopyLookupRequired = true; + + /** + * @var mixed The application supplied message of logging event. + */ + var $message; + + /** + * The application supplied message rendered through the log4php + * objet rendering mechanism. At present renderedMessage == message. + * @var string + */ + var $renderedMessage = null; + + /** + * The name of thread in which this logging event was generated. + * log4php saves here the process id via {@link PHP_MANUAL#getmypid getmypid()} + * @var mixed + */ + var $threadName = null; + + /** + * The number of seconds elapsed from 1/1/1970 until logging event + * was created plus microseconds if available. + * @var float + */ + public $timeStamp; + + /** + * @var LoggerLocationInfo Location information for the caller. + */ + var $locationInfo = null; + + /** + * Instantiate a LoggingEvent from the supplied parameters. + * + *
Except {@link $timeStamp} all the other fields of + * LoggerLoggingEvent are filled when actually needed. + * + * @param string $fqcn name of the caller class. + * @param mixed $logger The {@link Logger} category of this event or the logger name. + * @param LoggerLevel $priority The level of this event. + * @param mixed $message The message of this event. + * @param integer $timeStamp the timestamp of this logging event. + */ + public function __construct($fqcn, $logger, $priority, $message, $timeStamp = null) + { + $this->fqcn = $fqcn; + if ($logger instanceof Logger) { + $this->logger = $logger; + $this->categoryName = $logger->getName(); + } else { + $this->categoryName = strval($logger); + } + $this->level = $priority; + $this->message = $message; + if ($timeStamp !== null && is_float($timeStamp)) { + $this->timeStamp = $timeStamp; + } else { + if (function_exists('microtime')) { + // get microtime as float + $this->timeStamp = microtime(true); + } else { + $this->timeStamp = floatval(time()); + } + } + } + + /** + * Set the location information for this logging event. The collected + * information is cached for future use. + * + *
This method uses {@link PHP_MANUAL#debug_backtrace debug_backtrace()} function (if exists) + * to collect informations about caller.
+ *It only recognize informations generated by {@link Logger} and its subclasses.
+ * @return LoggerLocationInfo + */ + public function getLocationInformation() + { + if($this->locationInfo === null) { + + $locationInfo = array(); + + if (function_exists('debug_backtrace')) { + $trace = debug_backtrace(); + $prevHop = null; + // make a downsearch to identify the caller + $hop = array_pop($trace); + while ($hop !== null) { + $className = @strtolower($hop['class']); + if ( !empty($className) and ($className == 'logger' or $className == 'loggercategory' or + @strtolower(get_parent_class($className)) == 'logger' or + @strtolower(get_parent_class($className)) == 'loggercategory')) { + $locationInfo['line'] = $hop['line']; + $locationInfo['file'] = $hop['file']; + break; + } + $prevHop = $hop; + $hop = array_pop($trace); + } + $locationInfo['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main'; + if (isset($prevHop['function']) and + $prevHop['function'] !== 'include' and + $prevHop['function'] !== 'include_once' and + $prevHop['function'] !== 'require' and + $prevHop['function'] !== 'require_once') { + + $locationInfo['function'] = $prevHop['function']; + } else { + $locationInfo['function'] = 'main'; + } + } + + $this->locationInfo = new LoggerLocationInfo($locationInfo, $this->fqcn); + } + return $this->locationInfo; + } + + /** + * Return the level of this event. Use this form instead of directly + * accessing the {@link $level} field. + * @return LoggerLevel + */ + public function getLevel() + { + return $this->level; + } + + /** + * Return the name of the logger. Use this form instead of directly + * accessing the {@link $categoryName} field. + * @return string + */ + public function getLoggerName() + { + return $this->categoryName; + } + + /** + * Return the message for this logging event. + * + *Before serialization, the returned object is the message
+ * passed by the user to generate the logging event. After
+ * serialization, the returned value equals the String form of the
+ * message possibly after object rendering.
+ * @return mixed
+ */
+ public function getMessage()
+ {
+ if($this->message !== null) {
+ return $this->message;
+ } else {
+ return $this->getRenderedMessage();
+ }
+ }
+
+ /**
+ * This method returns the NDC for this event. It will return the
+ * correct content even if the event was generated in a different
+ * thread or even on a different machine. The {@link LoggerNDC::get()} method
+ * should never be called directly.
+ * @return string
+ */
+ public function getNDC()
+ {
+ if ($this->ndcLookupRequired) {
+ $this->ndcLookupRequired = false;
+ $this->ndc = implode(' ',LoggerNDC::get());
+ }
+ return $this->ndc;
+ }
+
+
+ /**
+ * Returns the the context corresponding to the key
+ * parameter.
+ * @return string
+ */
+ public function getMDC($key)
+ {
+ return LoggerMDC::get($key);
+ }
+
+ /**
+ * Render message.
+ * @return string
+ */
+ public function getRenderedMessage()
+ {
+ if($this->renderedMessage === null and $this->message !== null) {
+ if (is_string($this->message)) {
+ $this->renderedMessage = $this->message;
+ } else {
+ if ($this->logger !== null) {
+ $repository = $this->logger->getLoggerRepository();
+ } else {
+ $repository = LoggerManager::getLoggerRepository();
+ }
+ if (method_exists($repository, 'getRendererMap')) {
+ $rendererMap = $repository->getRendererMap();
+ $this->renderedMessage= $rendererMap->findAndRender($this->message);
+ } else {
+ $this->renderedMessage = (string)$this->message;
+ }
+ }
+ }
+ return $this->renderedMessage;
+ }
+
+ /**
+ * Returns the time when the application started, in seconds
+ * elapsed since 01.01.1970 plus microseconds if available.
+ *
+ * @return float
+ * @static
+ */
+ public static function getStartTime() {
+ if (!isset(self::$startTime)) {
+ if (function_exists('microtime')) {
+ // microtime as float
+ self::$startTime = microtime(true);
+ } else {
+ self::$startTime = floatval(time());
+ }
+ }
+ return self::$startTime;
+ }
+
+ /**
+ * @return float
+ */
+ public function getTimeStamp()
+ {
+ return $this->timeStamp;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getThreadName()
+ {
+ if ($this->threadName === null)
+ $this->threadName = (string)getmypid();
+ return $this->threadName;
+ }
+
+ /**
+ * @return mixed null
+ */
+ public function getThrowableInformation()
+ {
+ return null;
+ }
+
+ /**
+ * Serialize this object
+ * @return string
+ */
+ public function toString()
+ {
+ serialize($this);
+ }
+
+ /**
+ * Avoid serialization of the {@link $logger} object
+ */
+ public function __sleep()
+ {
+ return array(
+ 'fqcn','categoryName',
+ 'level',
+ 'ndc','ndcLookupRequired',
+ 'message','renderedMessage',
+ 'threadName',
+ 'timeStamp',
+ 'locationInfo'
+ );
+ }
+
+}
+
+LoggerLoggingEvent::getStartTime();
+
Index: branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerConfigurator.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerConfigurator.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerConfigurator.php (revision 18220)
@@ -0,0 +1,62 @@
+inherited.
+ * {@link LOG4PHP_LOGGER_CONFIGURATOR_NULL} is a synonym.
+ */
+define('LOG4PHP_LOGGER_CONFIGURATOR_INHERITED', 'inherited');
+
+/**
+ * Special level signifying inherited behaviour, same as
+ * {@link LOG4PHP_LOGGER_CONFIGURATOR_INHERITED}.
+ * The current value of this string constant is null.
+ */
+define('LOG4PHP_LOGGER_CONFIGURATOR_NULL', 'null');
+
+/**
+ * Implemented by classes capable of configuring log4php using a URL.
+ *
+ * @author Marco Vassura
+ * @version $Revision: 635069 $
+ * @package log4php
+ * @subpackage spi
+ */
+interface LoggerConfigurator {
+
+ /**
+ * Interpret a resource pointed by a url and configure accordingly.
+ *
+ * The configuration is done relative to the repository
+ * parameter.
+ *
+ * @param string $url The URL to parse
+ */
+ public static function configure($url=null);
+
+}
Index: branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerLocationInfo.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerLocationInfo.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerLocationInfo.php (revision 18220)
@@ -0,0 +1,126 @@
+NA is returned. Current value of this string
+ * constant is ?.
+ */
+define('LOG4PHP_LOGGER_LOCATION_INFO_NA', 'NA');
+
+/**
+ * The internal representation of caller location information.
+ *
+ * @author Marco Vassura
+ * @version $Revision: 635069 $
+ * @package log4php
+ * @subpackage spi
+ * @since 0.3
+ */
+class LoggerLocationInfo {
+
+ /**
+ * @var string Caller's line number.
+ */
+ protected $lineNumber = null;
+
+ /**
+ * @var string Caller's file name.
+ */
+ protected $fileName = null;
+
+ /**
+ * @var string Caller's fully qualified class name.
+ */
+ protected $className = null;
+
+ /**
+ * @var string Caller's method name.
+ */
+ protected $methodName = null;
+
+ /**
+ * @var string
+ */
+ protected $fullInfo = null;
+
+ /**
+ * Instantiate location information based on a {@link PHP_MANUAL#debug_backtrace}.
+ *
+ * @param array $trace
+ * @param mixed $caller
+ */
+ public function __construct($trace, $fqcn = null)
+ {
+ $this->lineNumber = isset($trace['line']) ? $trace['line'] : null;
+ $this->fileName = isset($trace['file']) ? $trace['file'] : null;
+ $this->className = isset($trace['class']) ? $trace['class'] : null;
+ $this->methodName = isset($trace['function']) ? $trace['function'] : null;
+
+ $this->fullInfo = $this->getClassName() . '.' . $this->getMethodName() .
+ '(' . $this->getFileName() . ':' . $this->getLineNumber() . ')';
+ }
+
+ public function getClassName()
+ {
+ return ($this->className === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->className;
+ }
+
+ /**
+ * Return the file name of the caller.
+ *
This information is not always available. + */ + public function getFileName() + { + return ($this->fileName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fileName; + } + + /** + * Returns the line number of the caller. + *
This information is not always available. + */ + public function getLineNumber() + { + return ($this->lineNumber === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->lineNumber; + } + + /** + * Returns the method name of the caller. + */ + public function getMethodName() + { + return ($this->methodName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->methodName; + } + + /** + * Returns the full information of the caller. + */ + public function getFullInfo() + { + return ($this->fullInfo === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fullInfo; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/spi/LoggerFilter.php (revision 18220) @@ -0,0 +1,119 @@ +This abstract class assumes and also imposes that filters be + * organized in a linear chain. The {@link #decide + * decide(LoggerLoggingEvent)} method of each filter is called sequentially, + * in the order of their addition to the chain. + * + *
The {@link decide()} method must return one + * of the integer constants {@link LOG4PHP_LOG4PHP_LOGGER_FILTER_DENY}, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_ACCEPT}. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_DENY} is returned, then the log event is + * dropped immediately without consulting with the remaining + * filters. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned, then the next filter + * in the chain is consulted. If there are no more filters in the + * chain, then the log event is logged. Thus, in the presence of no + * filters, the default behaviour is to log all logging events. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, then the log + * event is logged without consulting the remaining filters. + * + *
The philosophy of log4php filters is largely inspired from the + * Linux ipchains. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage spi + */ +class LoggerFilter { + + /** + * @var LoggerFilter Points to the next {@link LoggerFilter} in the filter chain. + */ + protected $next; + + /** + * Usually filters options become active when set. We provide a + * default do-nothing implementation for convenience. + */ + public function activateOptions() + { + return; + } + + /** + * Decide what to do. + *
If the decision is {@link LOG4PHP_LOGGER_FILTER_DENY}, then the event will be + * dropped. If the decision is {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}, then the next + * filter, if any, will be invoked. If the decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} then + * the event will be logged without consulting with other filters in + * the chain. + * + * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to decide upon. + * @return integer {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_DENY}|{@link LOG4PHP_LOGGER_FILTER_ACCEPT} + */ + public function decide($event) + { + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + } + + public function getNext() { + return $this->next; + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLevel.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLevel.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLevel.php (revision 18220) @@ -0,0 +1,266 @@ +OFF, FATAL, ERROR, + * WARN, INFODEBUG and + * ALL. + * + *
The LoggerLevel class may be subclassed to define a larger + * level set.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @since 0.5 + */ +class LoggerLevel { + + /** + * @var integer + */ + public $level; + + /** + * @var string + */ + public $levelStr; + + /** + * @var integer + */ + public $syslogEquivalent; + + /** + * Constructor + * + * @param integer $level + * @param string $levelStr + * @param integer $syslogEquivalent + */ + public function __construct($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 + */ + public function equals($o) + { + if ($o instanceof LoggerLevel) { + return ($this->level == $o->level); + } else { + return false; + } + } + + /** + * Returns an Off Level + * @static + * @return LoggerLevel + */ + public static 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 + */ + public static 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 + */ + public static 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 + */ + public static 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 + */ + public static 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 + */ + public static 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 + */ + public static 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 + */ + public function getSyslogEquivalent() + { + return $this->syslogEquivalent; + } + + /** + * Returns true if this level has a higher or equal + * level than the level passed as argument, false + * otherwise. + * + *You should think twice before overriding the default + * implementation of isGreaterOrEqual method. + * + * @param LoggerLevel $r + * @return boolean + */ + public function isGreaterOrEqual($r) + { + return $this->level >= $r->level; + } + + /** + * Returns the string representation of this priority. + * @return string + * @final + */ + public function toString() + { + return $this->levelStr; + } + + /** + * Returns the integer representation of this level. + * @return integer + */ + public 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 + */ + public static function toLevel($arg, $defaultLevel = null) + { + if ($defaultLevel === null) { + return self::toLevel($arg, self::getLevelDebug()); + } else { + if (is_int($arg)) { + switch($arg) { + case LOG4PHP_LEVEL_ALL_INT: return self::getLevelAll(); + case LOG4PHP_LEVEL_DEBUG_INT: return self::getLevelDebug(); + case LOG4PHP_LEVEL_INFO_INT: return self::getLevelInfo(); + case LOG4PHP_LEVEL_WARN_INT: return self::getLevelWarn(); + case LOG4PHP_LEVEL_ERROR_INT: return self::getLevelError(); + case LOG4PHP_LEVEL_FATAL_INT: return self::getLevelFatal(); + case LOG4PHP_LEVEL_OFF_INT: return self::getLevelOff(); + default: return $defaultLevel; + } + } else { + switch(strtoupper($arg)) { + case 'ALL': return self::getLevelAll(); + case 'DEBUG': return self::getLevelDebug(); + case 'INFO': return self::getLevelInfo(); + case 'WARN': return self::getLevelWarn(); + case 'ERROR': return self::getLevelError(); + case 'FATAL': return self::getLevelFatal(); + case 'OFF': return self::getLevelOff(); + default: return $defaultLevel; + } + } + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerPropertyConfigurator.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerPropertyConfigurator.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerPropertyConfigurator.php (revision 18220) @@ -0,0 +1,660 @@ +It is sometimes useful to see how log4php is reading configuration + * files. You can enable log4php internal logging by defining the + * log4php.debug variable.
+ * + *The LoggerPropertyConfigurator does not handle the + * advanced configuration features supported by the {@link LoggerDOMConfigurator} + * such as support for {@link LoggerFilter}, + custom {@link LoggerErrorHandlers}, nested appenders such as the + {@link Logger AsyncAppender}, + * etc. + * + *
All option values admit variable substitution. The + * syntax of variable substitution is similar to that of Unix + * shells. The string between an opening "${" and + * closing "}" is interpreted as a key. The value of + * the substituted variable can be defined as a system property or in + * the configuration file itself. The value of the key is first + * searched in the defined constants, in the enviroments variables + * and if not found there, it is + * then searched in the configuration file being parsed. The + * corresponding value replaces the ${variableName} sequence.
+ *For example, if $_ENV['home'] env var is set to + * /home/xyz, then every occurrence of the sequence + * ${home} will be interpreted as + * /home/xyz. See {@link LoggerOptionConverter::getSystemProperty()} + * for details.
+ * + *Please note that boolean values should be quoted otherwise the default
+ * value will be chosen. E.g.:
+ *
+ * // Does *not* work. Will always result in default value
+ * // (which is currently 'true' for this attribute).
+ * log4php.appender.A2.append=false
+ * // Does work.
+ * log4php.appender.A2.append="false"
+ *
+ *
The function {@link PHP_MANUAL#parse_ini_file} is used to read the + * file.
+ * + * The existing configuration is not cleared nor reset. + * If you require a different behavior, then call + * {@link LoggerManager::resetConfiguration()} + * method before calling {@link doConfigure()}. + * + *The configuration file consists of statements in the format + * key=value. The syntax of different configuration + * elements are discussed below. + * + *
Repository-wide threshold
+ * + *The repository-wide threshold filters logging requests by level + * regardless of logger. The syntax is: + * + *
+ * log4php.threshold=[level] + *+ * + *
The level value can consist of the string values OFF, FATAL, + * ERROR, WARN, INFO, DEBUG, ALL or a custom level value. A + * custom level value can be specified in the form + * level#classname. By default the repository-wide threshold is set + * to the lowest possible value, namely the level ALL. + *
+ * + * + *Appender configuration
+ * + *Appender configuration syntax is:
+ *+ * ; For appender named appenderName, set its class. + * ; Note: The appender name can contain dots. + * log4php.appender.appenderName=name_of_appender_class + * + * ; Set appender specific options. + * + * log4php.appender.appenderName.option1=value1 + * log4php.appender.appenderName.optionN=valueN + *+ * + * For each named appender you can configure its {@link LoggerLayout}. The + * syntax for configuring an appender's layout is: + *
+ * log4php.appender.appenderName.layout=name_of_layout_class + * log4php.appender.appenderName.layout.option1=value1 + * .... + * log4php.appender.appenderName.layout.optionN=valueN + *+ * + *
Configuring loggers
+ * + *The syntax for configuring the root logger is: + *
+ * log4php.rootLogger=[level], appenderName, appenderName, ... + *+ * + *
This syntax means that an optional level can be + * supplied followed by appender names separated by commas. + * + *
The level value can consist of the string values OFF, FATAL, + * ERROR, WARN, INFO, DEBUG, ALL or a custom level value. A + * custom level value can be specified in the form
+ * + *level#classname+ * + *
If a level value is specified, then the root level is set + * to the corresponding level. If no level value is specified, + * then the root level remains untouched. + * + *
The root logger can be assigned multiple appenders. + * + *
Each appenderName (separated by commas) will be added to + * the root logger. The named appender is defined using the + * appender syntax defined above. + * + *
For non-root categories the syntax is almost the same: + *
+ * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... + *+ * + *
The meaning of the optional level value is discussed above + * in relation to the root logger. In addition however, the value + * INHERITED can be specified meaning that the named logger should + * inherit its level from the logger hierarchy.
+ * + *If no level value is supplied, then the level of the + * named logger remains untouched.
+ * + *By default categories inherit their level from the + * hierarchy. However, if you set the level of a logger and later + * decide that that logger should inherit its level, then you should + * specify INHERITED as the value for the level value. NULL is a + * synonym for INHERITED.
+ * + *Similar to the root logger syntax, each appenderName + * (separated by commas) will be attached to the named logger.
+ * + *See the appender additivity rule in the user manual for + * the meaning of the additivity flag. + * + *
ObjectRenderers
+ * + *You can customize the way message objects of a given type are + * converted to String before being logged. This is done by + * specifying a {@link LoggerObjectRenderer} + * for the object type would like to customize.
+ * + *The syntax is: + * + *
+ * log4php.renderer.name_of_rendered_class=name_of_rendering.class + *+ * + * As in, + *
+ * log4php.renderer.myFruit=myFruitRenderer + *+ * + *
Logger Factories
+ * + * The usage of custom logger factories is discouraged and no longer + * documented. + * + *Example
+ * + *An example configuration is given below. Other configuration + * file examples are given in the tests folder. + * + *
+ * ; Set options for appender named "A1". + * ; Appender "A1" will be a LoggerAppenderSyslog + * log4php.appender.A1=LoggerAppenderSyslog + * + * ; The syslog daemon resides on www.abc.net + * log4php.appender.A1.ident=log4php-test + * + * ; A1's layout is a LoggerPatternLayout, using the conversion pattern + * ; %r %-5p %c{2} %M.%L %x - %m%n. Thus, the log output will + * ; include the relative time since the start of the application in + * ; milliseconds, followed by the level of the log request, + * ; followed by the two rightmost components of the logger name, + * ; followed by the callers method name, followed by the line number, + * ; the nested disgnostic context and finally the message itself. + * ; Refer to the documentation of LoggerPatternLayout} for further information + * ; on the syntax of the ConversionPattern key. + * log4php.appender.A1.layout=LoggerPatternLayout + * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" + * + * ; Set options for appender named "A2" + * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB + * ; using at most one backup file. A2's layout is TTCC, using the + * ; ISO8061 date format with context printing enabled. + * log4php.appender.A2=LoggerAppenderRollingFile + * log4php.appender.A2.MaxFileSize=10MB + * log4php.appender.A2.MaxBackupIndex=1 + * log4php.appender.A2.layout=LoggerLayoutTTCC + * log4php.appender.A2.layout.ContextPrinting="true" + * log4php.appender.A2.layout.DateFormat="%c" + * + * ; Root logger set to DEBUG using the A2 appender defined above. + * log4php.rootLogger=DEBUG, A2 + * + * ; Logger definitions: + * ; The SECURITY logger inherits is level from root. However, it's output + * ; will go to A1 appender defined above. It's additivity is non-cumulative. + * log4php.logger.SECURITY=INHERIT, A1 + * log4php.additivity.SECURITY=false + * + * ; Only warnings or above will be logged for the logger "SECURITY.access". + * ; Output will go to A1. + * log4php.logger.SECURITY.access=WARN + * + * + * ; The logger "class.of.the.day" inherits its level from the + * ; logger hierarchy. Output will go to the appender's of the root + * ; logger, A2 in this case. + * log4php.logger.class.of.the.day=INHERIT + *+ * + *
Refer to the setOption method in each Appender and + * Layout for class specific options.
+ * + *Use the ";" character at the + * beginning of a line for comments.
+ * + * @param string $url The name of the configuration file where the + * configuration information is stored. + * @param LoggerHierarchy &$repository the repository to apply the configuration + */ + function doConfigure($url, &$repository) + { + $properties = @parse_ini_file($url); + if ($properties === false) { + LoggerLog::warn("LoggerPropertyConfigurator::doConfigure() cannot load '$url' configuration."); + return false; + } + return $this->doConfigureProperties($properties, $repository); + } + + + /** + * Read configuration options from properties. + * + * @see doConfigure(). + * @param array $properties + * @param LoggerHierarchy &$hierarchy + */ + function doConfigureProperties($properties, &$hierarchy) + { + $value = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY]; + + if (!empty($value)) { + LoggerLog::internalDebugging(LoggerOptionConverter::toBoolean($value, LoggerLog::internalDebugging())); + } + + $thresholdStr = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX]; + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); + + $this->configureRootCategory($properties, $hierarchy); + $this->configureLoggerFactory($properties); + $this->parseCatsAndRenderers($properties, $hierarchy); + + LoggerLog::debug("LoggerPropertyConfigurator::doConfigureProperties() Finished configuring."); + + return true; + } + + // -------------------------------------------------------------------------- + // Internal stuff + // -------------------------------------------------------------------------- + + /** + * Check the provided Properties object for a + * {@link LoggerFactory} entry specified by + * {@link LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY}. + * + * If such an entry exists, an attempt is made to create an instance using + * the default constructor. + * This instance is used for subsequent Category creations + * within this configurator. + * + * @see parseCatsAndRenderers() + * @param array $props array of properties + */ + function configureLoggerFactory($props) + { + $factoryFqcn = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY]; + if(!empty($factoryFqcn)) { + $factoryClassName = basename($factoryFqcn); + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() Trying to load factory [" . + $factoryClassName . + "]." + ); + + if (!class_exists($factoryClassName)) + @include_once("{$factoryFqcn}.php"); + if (class_exists($factoryClassName)) { + $loggerFactory = new $factoryClassName(); + } else { + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() Unable to load factory [" . + $factoryClassName . + "]. Using default." + ); + $loggerFactory = $this->loggerFactory; + } + + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() ". + "Setting properties for category factory [" . get_class($loggerFactory) . "]." + ); + + LoggerPropertySetter::setPropertiesByObject($loggerFactory, $props, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX . "."); + } + } + + /** + * @param array $props array of properties + * @param LoggerHierarchy &$hierarchy + */ + function configureRootCategory($props, &$hierarchy) + { + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX; + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX]; + + if(empty($value)) { + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX]; + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX; + } + + if (empty($value)) { + LoggerLog::debug( + "LoggerPropertyConfigurator::configureRootCategory() ". + "Could not find root logger information. Is this OK?" + ); + } else { + $root = $hierarchy->getRootLogger(); + // synchronized(root) { + $this->parseCategory( + $props, + $root, + $effectivePrefix, + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME, + $value + ); + // } + } + } + + /** + * Parse non-root elements, such non-root categories and renderers. + * + * @param array $props array of properties + * @param LoggerHierarchy &$hierarchy + */ + function parseCatsAndRenderers($props, &$hierarchy) + { + while(list($key,$value) = each($props)) { + if( strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0 or + strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { + if(strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0) { + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX)); + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX)); + } + $logger =& $hierarchy->getLogger($loggerName, $this->loggerFactory); + // synchronized(logger) { + $this->parseCategory($props, $logger, $key, $loggerName, $value); + $this->parseAdditivityForLogger($props, $logger, $loggerName); + // } + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX) === 0) { + $renderedClass = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX)); + $renderingClass = $value; + if (method_exists($hierarchy, 'addrenderer')) { // ? + LoggerRendererMap::addRenderer($hierarchy, $renderedClass, $renderingClass); + } + } + } + } + + /** + * Parse the additivity option for a non-root category. + * + * @param array $props array of properties + * @param Logger &$cat + * @param string $loggerName + */ + function parseAdditivityForLogger($props, &$cat, $loggerName) + { + $value = LoggerOptionConverter::findAndSubst( + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName, + $props + ); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAdditivityForLogger() ". + "Handling " . LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName . "=[{$value}]" + ); + // touch additivity only if necessary + if(!empty($value)) { + $additivity = LoggerOptionConverter::toBoolean($value, true); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAdditivityForLogger() ". + "Setting additivity for [{$loggerName}] to [{$additivity}]" + ); + $cat->setAdditivity($additivity); + } + } + + /** + * This method must work for the root category as well. + * + * @param array $props array of properties + * @param Logger &$logger + * @param string $optionKey + * @param string $loggerName + * @param string $value + * @return Logger + */ + public function parseCategory($props, &$logger, $optionKey, $loggerName, $value) { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Parsing for [{$loggerName}] with value=[{$value}]." + ); + + // We must skip over ',' but not white space + $st = explode(',', $value); + + // If value is not in the form ", appender.." or "", then we should set + // the level of the loggeregory. + + if(!(empty($value) || @$value[0] == ',')) { + // just to be on the safe side... + if(sizeof($st) == 0) + return; + + $levelStr = current($st); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Level token is [$levelStr]." + ); + + // If the level value is inherited, set category level value to + // null. We also check that the user has not specified inherited for the + // root category. + if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { + if ($loggerName == LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseCategory() ". + "The root logger cannot be set to null." + ); + } else { + $logger->setLevel(null); + } + } else { + $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); + } + } + + // Begin by removing all existing appenders. + $logger->removeAllAppenders(); + while($appenderName = next($st)) { + $appenderName = trim($appenderName); + if(empty($appenderName)) + continue; + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Parsing appender named [{$appenderName}]." + ); + $appender =& $this->parseAppender($props, $appenderName); + if($appender !== null) { + $logger->addAppender($appender); + } + } + } + + /** + * @param array $props array of properties + * @param string $appenderName + * @return LoggerAppender + */ + function &parseAppender($props, $appenderName) + { + $appender = LoggerAppender::singleton($appenderName); + if($appender !== null) { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Appender [{$appenderName}] was already parsed." + ); + return $appender; + } + // Appender was not previously initialized. + $prefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX . $appenderName; + $layoutPrefix = $prefix . ".layout"; + $appenderClass = @$props[$prefix]; + if (!empty($appenderClass)) { + $appender = LoggerAppender::singleton($appenderName, $appenderClass); + if($appender === null) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "Could not instantiate appender named [$appenderName]." + ); + return null; + } + } else { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "Could not instantiate appender named [$appenderName] with null className." + ); + return null; + } + + $appender->setName($appenderName); + if( $appender->requiresLayout() ) { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsing layout section for [$appenderName]." + ); + $layoutClass = @$props[$layoutPrefix]; + $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); + if (empty($layoutClass)) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "layout class is empty in '$layoutPrefix'. Using Simple layout" + ); + $layout = LoggerLayout::factory('LoggerLayoutSimple'); + } else { + $layout = LoggerLayout::factory($layoutClass); + + if($layout === null) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "cannot create layout '$layoutClass'. Using Simple layout" + ); + $layout = LoggerLayout::factory('LoggerLayoutSimple'); + } + } + + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsing layout options for [$appenderName]." + ); + LoggerPropertySetter::setPropertiesByObject($layout, $props, $layoutPrefix . "."); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "End Parsing layout options for [$appenderName]." + ); + $appender->setLayout($layout); + + } + LoggerPropertySetter::setPropertiesByObject($appender, $props, $prefix . "."); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsed [{$appenderName}] options." + ); + return $appender; + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/xml/LoggerDOMConfigurator.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/xml/LoggerDOMConfigurator.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/xml/LoggerDOMConfigurator.php (revision 18220) @@ -0,0 +1,611 @@ + +Read the log4php.dtd included in the documentation directory. Note that + * php parser does not validate the document.
+ * + *Sometimes it is useful to see how log4php is reading configuration + * files. You can enable log4php internal logging by setting the debug + * attribute in the log4php:configuration element. As in + *
+ * <log4php:configuration debug="true" xmlns:log4php="http://logging.apache.org/log4php/"> + * ... + * </log4php:configuration> + *+ * + *
There are sample XML files included in the package under tests/ + * subdirectories.
+ * + * @author Marco Vassura + * @author Knut UrdalenIt does not output a complete well-formed XML file. + * The output is designed to be included as an external entity in a separate file to form + * a correct XML file.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage layouts + */ +class LoggerXmlLayout extends LoggerLayout { + + /** + * The LocationInfo option takes a boolean value. By default, + * it is set to false which means there will be no location + * information output by this layout. If the the option is set to + * true, then the file name and line number of the statement at the + * origin of the log statement will be output. + * @var boolean + */ + var $locationInfo = true; + + /** + * @var boolean set the elements namespace + */ + var $log4jNamespace = false; + + + /** + * @var string namespace + * @private + */ + var $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; + + /** + * @var string namespace prefix + * @private + */ + var $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; + + /** + * No options to activate. + */ + function activateOptions() + { + if ($this->getLog4jNamespace()) { + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS; + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX; + } else { + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; + } + } + + /** + * @return string + */ + function getHeader() + { + return "<{$this->_namespacePrefix}:eventSet ". + "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ". + "version=\"0.3\" ". + "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"". + ">\r\n"; + } + + /** + * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. + * + * @param LoggerLoggingEvent $event + * @return string + */ + function format($event) + { + $loggerName = $event->getLoggerName(); + $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', ''); + $thread = $event->getThreadName(); + $level = $event->getLevel(); + $levelStr = $level->toString(); + + $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n"; + $buf .= "<{$this->_namespacePrefix}:message>getRenderedMessage()); + $buf .= "]]>{$this->_namespacePrefix}:message>\r\n"; + + $ndc = $event->getNDC(); + if($ndc != null) { + $buf .= "<{$this->_namespacePrefix}:NDC>{$this->_namespacePrefix}:NDC>\r\n"; + } + + if ($this->getLocationInfo()) { + $locationInfo = $event->getLocationInformation(); + $buf .= "<{$this->_namespacePrefix}:locationInfo ". + "class=\"" . $locationInfo->getClassName() . "\" ". + "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ". + "line=\"" . $locationInfo->getLineNumber() . "\" ". + "method=\"" . $locationInfo->getMethodName() . "\" "; + $buf .= "/>\r\n"; + + } + + $buf .= "{$this->_namespacePrefix}:event>\r\n\r\n"; + + return $buf; + + } + + /** + * @return string + */ + function getFooter() + { + + return "{$this->_namespacePrefix}:eventSet>\r\n"; + } + + /** + * @return boolean + */ + function getLocationInfo() + { + return $this->locationInfo; + } + + /** + * @return boolean + */ + function getLog4jNamespace() + { + return $this->log4jNamespace; + } + + /** + * The XMLLayout prints and does not ignore exceptions. Hence the + * return value false. + * @return boolean + */ + function ignoresThrowable() + { + return false; + } + + /** + * The {@link $locationInfo} option takes a boolean value. By default, + * it is set to false which means there will be no location + * information output by this layout. If the the option is set to + * true, then the file name and line number of the statement at the + * origin of the log statement will be output. + */ + function setLocationInfo($flag) + { + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true); + } + + /** + * @param boolean + */ + function setLog4jNamespace($flag) + { + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true); + } +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerLayoutHtml.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerLayoutHtml.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerLayoutHtml.php (revision 18220) @@ -0,0 +1,258 @@ +LocationInfo option takes a boolean value. By + * default, it is set to false which means there will be no location + * information output by this layout. If the the option is set to + * true, then the file name and line number of the statement + * at the origin of the log statement will be output. + * + *If you are embedding this layout within a {@link LoggerAppenderMail} + * or a {@link LoggerAppenderMailEvent} then make sure to set the + * LocationInfo option of that appender as well. + * @var boolean + */ + var $locationInfo = false; + + /** + * The Title option takes a String value. This option sets the + * document title of the generated HTML document. + * Defaults to 'Log4php Log Messages'. + * @var string + */ + var $title = "Log4php Log Messages"; + + /** + * Constructor + */ + function LoggerLayoutHtml() + { + return; + } + + /** + * The LocationInfo option takes a boolean value. By + * default, it is set to false which means there will be no location + * information output by this layout. If the the option is set to + * true, then the file name and line number of the statement + * at the origin of the log statement will be output. + * + *
If you are embedding this layout within a {@link LoggerAppenderMail} + * or a {@link LoggerAppenderMailEvent} then make sure to set the + * LocationInfo option of that appender as well. + */ + function setLocationInfo($flag) + { + if (is_bool($flag)) { + $this->locationInfo = $flag; + } else { + $this->locationInfo = (bool)(strtolower($flag) == 'true'); + } + } + + /** + * Returns the current value of the LocationInfo option. + */ + function getLocationInfo() + { + return $this->locationInfo; + } + + /** + * The Title option takes a String value. This option sets the + * document title of the generated HTML document. + * Defaults to 'Log4php Log Messages'. + */ + function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string Returns the current value of the Title option. + */ + function getTitle() + { + return $this->title; + } + + /** + * @return string Returns the content type output by this layout, i.e "text/html". + */ + function getContentType() + { + return "text/html"; + } + + /** + * No options to activate. + */ + function activateOptions() + { + return true; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function format($event) + { + $sbuf = LOG4PHP_LINE_SEP . "
Time | " . LOG4PHP_LINE_SEP; + $sbuf .= "Thread | " . LOG4PHP_LINE_SEP; + $sbuf .= "Level | " . LOG4PHP_LINE_SEP; + $sbuf .= "Category | " . LOG4PHP_LINE_SEP; + if ($this->locationInfo) + $sbuf .= "File:Line | " . LOG4PHP_LINE_SEP; + $sbuf .= "Message | " . LOG4PHP_LINE_SEP; + $sbuf .= "
---|
Each of the four fields can be individually enabled or + * disabled. The time format depends on the DateFormat used.
+ * + *If no dateFormat is specified it defaults to '%c'. + * See php {@link PHP_MANUAL#date} function for details.
+ * + * Params: + * - {@link $threadPrinting} (true|false) enable/disable pid reporting. + * - {@link $categoryPrefixing} (true|false) enable/disable logger category reporting. + * - {@link $contextPrinting} (true|false) enable/disable NDC reporting. + * - {@link $microSecondsPrinting} (true|false) enable/disable micro seconds reporting in timestamp. + * - {@link $dateFormat} (string) set date format. See php {@link PHP_MANUAL#date} function for details. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage layouts + */ +class LoggerLayoutTTCC extends LoggerLayout { + + // Internal representation of options + protected $threadPrinting = true; + protected $categoryPrefixing = true; + protected $contextPrinting = true; + protected $microSecondsPrinting = true; + + /** + * @var string date format. See {@link PHP_MANUAL#strftime} for details + */ + protected $dateFormat = '%c'; + + /** + * Constructor + * + * @param string date format + * @see dateFormat + */ + public function __construct($dateFormat = '') + { + if (!empty($dateFormat)) + $this->dateFormat = $dateFormat; + return; + } + + public function activateOptions() { + return; + } + + /** + * The ThreadPrinting option specifies whether the name of the + * current thread is part of log output or not. This is true by default. + */ + public function setThreadPrinting($threadPrinting) + { + + $this->threadPrinting = is_bool($threadPrinting) ? + $threadPrinting : + (bool)(strtolower($threadPrinting) == 'true'); + } + + /** + * @return boolean Returns value of the ThreadPrinting option. + */ + public function getThreadPrinting() { + return $this->threadPrinting; + } + + /** + * The CategoryPrefixing option specifies whether {@link Category} + * name is part of log output or not. This is true by default. + */ + public function setCategoryPrefixing($categoryPrefixing) + { + $this->categoryPrefixing = is_bool($categoryPrefixing) ? + $categoryPrefixing : + (bool)(strtolower($categoryPrefixing) == 'true'); + } + + /** + * @return boolean Returns value of the CategoryPrefixing option. + */ + public function getCategoryPrefixing() { + return $this->categoryPrefixing; + } + + /** + * The ContextPrinting option specifies log output will include + * the nested context information belonging to the current thread. + * This is true by default. + */ + public function setContextPrinting($contextPrinting) { + $this->contextPrinting = is_bool($contextPrinting) ? + $contextPrinting : + (bool)(strtolower($contextPrinting) == 'true'); + } + + /** + * @return boolean Returns value of the ContextPrinting option. + */ + public function getContextPrinting() + { + return $this->contextPrinting; + } + + /** + * The MicroSecondsPrinting option specifies if microseconds infos + * should be printed at the end of timestamp. + * This is true by default. + */ + public function setMicroSecondsPrinting($microSecondsPrinting) { + $this->microSecondsPrinting = is_bool($microSecondsPrinting) ? + $microSecondsPrinting : + (bool)(strtolower($microSecondsPrinting) == 'true'); + } + + /** + * @return boolean Returns value of the MicroSecondsPrinting option. + */ + public function getMicroSecondsPrinting() + { + return $this->microSecondsPrinting; + } + + + public function setDateFormat($dateFormat) + { + $this->dateFormat = $dateFormat; + } + + /** + * @return string + */ + public function getDateFormat() + { + return $this->dateFormat; + } + + /** + * In addition to the level of the statement and message, the + * returned string includes time, thread, category. + *Time, thread, category are printed depending on options. + * + * @param LoggerLoggingEvent $event + * @return string + */ + public function format($event) + { + $timeStamp = (float)$event->getTimeStamp(); + $format = strftime($this->dateFormat, (int)$timeStamp); + + if ($this->microSecondsPrinting) { + $usecs = floor(($timeStamp - (int)$timeStamp) * 1000); + $format .= sprintf(',%03d', $usecs); + } + + $format .= ' '; + + if ($this->threadPrinting) + $format .= '['.getmypid().'] '; + + $level = $event->getLevel(); + $format .= $level->toString().' '; + + if($this->categoryPrefixing) { + $format .= $event->getLoggerName().' '; + } + + if($this->contextPrinting) { + $ndc = $event->getNDC(); + if($ndc != null) { + $format .= $ndc.' '; + } + } + + $format .= '- '.$event->getRenderedMessage(); + $format .= LOG4PHP_LINE_SEP; + + return $format; + } + + public function ignoresThrowable() + { + return true; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerPatternLayout.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerPatternLayout.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/layouts/LoggerPatternLayout.php (revision 18220) @@ -0,0 +1,262 @@ +The goal of this class is to {@link format()} a {@link LoggerLoggingEvent} and return the results as a string. + * The results depend on the conversion pattern. + * The conversion pattern is closely related to the conversion pattern of the printf function in C. + * A conversion pattern is composed of literal text and format control expressions called conversion specifiers. + * You are free to insert any literal text within the conversion pattern.
+ * + *Each conversion specifier starts with a percent sign (%) and is followed by optional + * format modifiers and a conversion character.
+ * + *The conversion character specifies the type of data, e.g. category, priority, date, thread name. + * The format modifiers control such things as field width, padding, left and right justification.
+ * + * The following is a simple example. + * + *Let the conversion pattern be "%-5p [%t]: %m%n" and assume that the log4php environment + * was set to use a LoggerPatternLayout.
+ * + * Then the statements + *
+ * $root =& LoggerManager::getRoot();
+ * $root->debug("Message 1");
+ * $root->warn("Message 2");
+ *
+ * would yield the output
+ * + * DEBUG [main]: Message 1 + * WARN [main]: Message 2 + *+ * + *
Note that there is no explicit separator between text and conversion specifiers.
+ * + *The pattern parser knows when it has reached the end of a conversion specifier when it reads a conversion character. + * In the example above the conversion specifier %-5p means the priority of the logging event should be + * left justified to a width of five characters.
+ * + * Not all log4j conversion characters are implemented. The recognized conversion characters are: + * - c Used to output the category of the logging event. The category conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. + * If a precision specifier is given, then only the corresponding number of right most components of the category name will be printed. + * By default the category name is printed in full. + * For example, for the category name "a.b.c" the pattern %c{2} will output "b.c". + * - C Used to output the fully qualified class name of the caller issuing the logging request. + * This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. + * If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. + * By default the class name is output in fully qualified form. + * For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass". + * - d Used to output the date of the logging event. + * The date conversion specifier may be followed by a date format specifier enclosed between braces. + * The format specifier follows the {@link PHP_MANUAL#date} function. + * Note that the special character u is used to as microseconds replacement (to avoid replacement, + * use \u). + * For example, %d{H:i:s,u} or %d{d M Y H:i:s,u}. If no date format specifier is given then ISO8601 format is assumed. + * The date format specifier admits the same syntax as the time pattern string of the SimpleDateFormat. + * It is recommended to use the predefined log4php date formatters. + * These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying + * AbsoluteTimeDateFormat, DateTimeDateFormat and respectively ISO8601DateFormat. + * For example, %d{ISO8601} or %d{ABSOLUTE}. + * - F Used to output the file name where the logging request was issued. + * - l Used to output location information of the caller which generated the logging event. + * - L Used to output the line number from where the logging request was issued. + * - m Used to output the application supplied message associated with the logging event. + * - M Used to output the method name where the logging request was issued. + * - p Used to output the priority of the logging event. + * - r Used to output the number of milliseconds elapsed since the start of + * the application until the creation of the logging event. + * - t Used to output the name of the thread that generated the logging event. + * - x Used to output the NDC (nested diagnostic context) associated with + * the thread that generated the logging event. + * - X Used to output the MDC (mapped diagnostic context) associated with + * the thread that generated the logging event. + * The X conversion character must be followed by the key for the map placed between braces, + * as in %X{clientNumber} where clientNumber is the key. + * The value in the MDC corresponding to the key will be output. + * See {@link LoggerMDC} class for more details. + * - % The sequence %% outputs a single percent sign. + * + *By default the relevant information is output as is. + * However, with the aid of format modifiers it is possible to change the minimum field width, + * the maximum field width and justification.
+ * + *The optional format modifier is placed between the percent sign and the conversion character.
+ *The first optional format modifier is the left justification flag which is just the minus (-) character. + * Then comes the optional minimum field width modifier. + * This is a decimal constant that represents the minimum number of characters to output. + * If the data item requires fewer characters, it is padded on either the left or the right until the minimum width is reached. The default is to pad on the left (right justify) but you can specify right padding with the left justification flag. The padding character is space. If the data item is larger than the minimum field width, the field is expanded to accommodate the data. + * The value is never truncated.
+ * + *This behavior can be changed using the maximum field width modifier which is designated by a period + * followed by a decimal constant. + * If the data item is longer than the maximum field, + * then the extra characters are removed from the beginning of the data item and not from the end. + * For example, it the maximum field width is eight and the data item is ten characters long, + * then the first two characters of the data item are dropped. + * This behavior deviates from the printf function in C where truncation is done from the end.
+ * + *Below are various format modifier examples for the category conversion specifier.
+ *+ * Format modifier left justify minimum width maximum width comment + * %20c false 20 none Left pad with spaces if the category name + * is less than 20 characters long. + * %-20c true 20 none Right pad with spaces if the category name + * is less than 20 characters long. + * %.30c NA none 30 Truncate from the beginning if the category name + * is longer than 30 characters. + * %20.30c false 20 30 Left pad with spaces if the category name + * is shorter than 20 characters. + * However, if category name is longer than 30 chars, + * then truncate from the beginning. + * %-20.30c true 20 30 Right pad with spaces if the category name is + * shorter than 20 chars. + * However, if category name is longer than 30 chars, + * then truncate from the beginning. + *+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage layouts + * @since 0.3 + */ +class LoggerPatternLayout extends LoggerLayout { + + /** + * @var string output buffer appended to when format() is invoked + */ + var $sbuf; + + /** + * @var string + */ + var $pattern; + + /** + * @var LoggerPatternConverter head chain + */ + var $head; + + var $timezone; + + /** + * Constructs a PatternLayout using the + * {@link LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_LAYOUT_PATTERN}. + * The default pattern just produces the application supplied message. + */ + function LoggerPatternLayout($pattern = null) + { + if ($pattern === null) { + $this->LoggerPatternLayout(LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_CONVERSION_PATTERN); + } else { + $this->pattern = $pattern; + } + } + + /** + * Set the ConversionPattern option. This is the string which + * controls formatting and consists of a mix of literal content and + * conversion specifiers. + */ + function setConversionPattern($conversionPattern) + { + $this->pattern = $conversionPattern; + $patternParser = $this->createPatternParser($this->pattern); + $this->head = $patternParser->parse(); + } + + /** + * @return string Returns the value of the ConversionPattern option. + */ + function getConversionPattern() + { + return $this->pattern; + } + + /** + * Does not do anything as options become effective + */ + function activateOptions() + { + // nothing to do. + } + + function ignoresThrowable() + { + return true; + } + + /** + * Returns LoggerPatternParser used to parse the conversion string. Subclasses + * may override this to return a subclass of PatternParser which recognize + * custom conversion characters. + * + * @param string $pattern + * @return LoggerPatternParser + */ + function createPatternParser($pattern) + { + return new LoggerPatternParser($pattern); + } + + /** + * Produces a formatted string as specified by the conversion pattern. + * + * @param LoggerLoggingEvent $event + * @return string + */ + function format($event) + { + LoggerLog::debug("LoggerPatternLayout::format()"); + + // Reset working stringbuffer + $this->sbuf = ''; + $c = $this->head; + while($c !== null) { + $c->format($this->sbuf, $event); + $c = $c->next; + } + return $this->sbuf; + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LICENSE.txt =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LICENSE.txt (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LICENSE.txt (revision 18220) @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerDefaultCategoryFactory.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerDefaultCategoryFactory.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerDefaultCategoryFactory.php (revision 18220) @@ -0,0 +1,49 @@ +exists($name); + } + + /** + * Returns an array this whole Logger instances. + * + * @static + * @see Logger + * @return array + */ + public static function getCurrentLoggers() + { + return self::getLoggerRepository()->getCurrentLoggers(); + } + + /** + * Returns the root logger. + * + * @static + * @return object + * @see LoggerRoot + */ + public static function getRootLogger() + { + return self::getLoggerRepository()->getRootLogger(); + } + + /** + * Returns the specified Logger. + * + * @param string $name logger name + * @param LoggerFactory $factory a {@link LoggerFactory} instance or null + * @static + * @return Logger + */ + public static function getLogger($name, $factory = null) + { + return self::getLoggerRepository()->getLogger($name, $factory); + } + + /** + * Returns the LoggerHierarchy. + * + * @static + * @return LoggerHierarchy + */ + public static function getLoggerRepository() + { + return LoggerHierarchy::singleton(); + } + + + /** + * Destroy loggers object tree. + * + * @static + * @return boolean + */ + public static function resetConfiguration() + { + return self::getLoggerRepository()->resetConfiguration(); + } + + /** + * Does nothing. + * @static + */ + public static function setRepositorySelector($selector, $guard) + { + return; + } + + /** + * Safely close all appenders. + * @static + */ + public static function shutdown() + { + return self::getLoggerRepository()->shutdown(); + } +} + +// --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- + +if (!defined('LOG4PHP_DEFAULT_INIT_OVERRIDE')) { + if (isset($_ENV['log4php.defaultInitOverride'])) { + /** + * @ignore + */ + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', + LoggerOptionConverter::toBoolean($_ENV['log4php.defaultInitOverride'], false) + ); + } elseif (isset($GLOBALS['log4php.defaultInitOverride'])) { + /** + * @ignore + */ + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', + LoggerOptionConverter::toBoolean($GLOBALS['log4php.defaultInitOverride'], false) + ); + } else { + /** + * Controls init execution + * + * With this constant users can skip the default init procedure that is + * called when this file is included. + * + *
If it is not user defined, log4php tries to autoconfigure using (in order):
+ * + * - the$_ENV['log4php.defaultInitOverride']
variable.
+ * - the $GLOBALS['log4php.defaultInitOverride']
global variable.
+ * - defaults to false
+ *
+ * @var boolean
+ */
+ define('LOG4PHP_DEFAULT_INIT_OVERRIDE', false);
+ }
+}
+
+if (!defined('LOG4PHP_CONFIGURATION')) {
+ if (isset($_ENV['log4php.configuration'])) {
+ /**
+ * @ignore
+ */
+ define('LOG4PHP_CONFIGURATION', trim($_ENV['log4php.configuration']));
+ } else {
+ /**
+ * Configuration file.
+ *
+ * This constant tells configurator classes where the configuration + * file is located.
+ *If not set by user, log4php tries to set it automatically using + * (in order):
+ * + * - the$_ENV['log4php.configuration']
enviroment variable.
+ * - defaults to 'log4php.properties'.
+ *
+ * @var string
+ */
+ define('LOG4PHP_CONFIGURATION', 'log4php.properties');
+ }
+}
+
+if (!defined('LOG4PHP_CONFIGURATOR_CLASS')) {
+ if ( strtolower(substr( LOG4PHP_CONFIGURATION, -4 )) == '.xml') {
+ /**
+ * @ignore
+ */
+ define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/xml/LoggerDOMConfigurator');
+ } else {
+ /**
+ * Holds the configurator class name.
+ *
+ * This constant is set with the fullname (path included but non the + * .php extension) of the configurator class that init procedure will use.
+ *If not set by user, log4php tries to set it automatically.
+ *If {@link LOG4PHP_CONFIGURATION} has '.xml' extension set the + * constants to '{@link LOG4PHP_DIR}/xml/{@link LoggerDOMConfigurator}'.
+ *Otherwise set the constants to + * '{@link LOG4PHP_DIR}/{@link LoggerPropertyConfigurator}'.
+ * + *Security Note: classfile pointed by this constant will be brutally
+ * included with a:
+ * @include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");
This procedure tries to configure the {@link LoggerHierarchy} using the + * configurator class defined via {@link LOG4PHP_CONFIGURATOR_CLASS} that tries + * to load the configurator file defined in {@link LOG4PHP_CONFIGURATION}. + * If something goes wrong a warn is raised.
+ *Users can skip this procedure using {@link LOG4PHP_DEFAULT_INIT_OVERRIDE} + * constant.
+ * + * @return boolean + */ +function LoggerManagerDefaultInit() +{ + $configuratorClass = basename(LOG4PHP_CONFIGURATOR_CLASS); + if (!class_exists($configuratorClass)) { + include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php"); + } + if (class_exists($configuratorClass)) { + + return call_user_func(array($configuratorClass, 'configure'), LOG4PHP_CONFIGURATION); + + } else { + LoggerLog::warn("LoggerManagerDefaultInit() Configurator '{$configuratorClass}' doesnt exists"); + return false; + } +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerStringMatchFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerStringMatchFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerStringMatchFilter.php (revision 18220) @@ -0,0 +1,110 @@ +The filter admits two options {@link $stringToMatch} and + * {@link $acceptOnMatch}. If there is a match (using {@link PHP_MANUAL#strpos} + * between the value of the {@link $stringToMatch} option and the message + * of the {@link LoggerLoggingEvent}, + * then the {@link decide()} method returns {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if + * the AcceptOnMatch option value is true, if it is false then + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match, {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} + * is returned. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage varia + * @since 0.3 + */ +class LoggerStringMatchFilter extends LoggerFilter { + + /** + * @var boolean + */ + var $acceptOnMatch = true; + + /** + * @var string + */ + var $stringToMatch = null; + + /** + * @return boolean + */ + function getAcceptOnMatch() + { + return $this->acceptOnMatch; + } + + /** + * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') + */ + function setAcceptOnMatch($acceptOnMatch) + { + $this->acceptOnMatch = is_bool($acceptOnMatch) ? + $acceptOnMatch : + (bool)(strtolower($acceptOnMatch) == 'true'); + } + + /** + * @return string + */ + function getStringToMatch() + { + return $this->stringToMatch; + } + + /** + * @param string $s the string to match + */ + function setStringToMatch($s) + { + $this->stringToMatch = $s; + } + + /** + * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. + */ + function decide($event) + { + $msg = $event->getRenderedMessage(); + + if($msg === null or $this->stringToMatch === null) + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + if( strpos($msg, $this->stringToMatch) !== false ) { + return ($this->acceptOnMatch) ? LOG4PHP_LOGGER_FILTER_ACCEPT : LOG4PHP_LOGGER_FILTER_DENY ; + } + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelMatchFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelMatchFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelMatchFilter.php (revision 18220) @@ -0,0 +1,121 @@ +The filter admits two options LevelToMatch and + * AcceptOnMatch. If there is an exact match between the value + * of the LevelToMatch option and the level of the + * {@link LoggerLoggingEvent}, then the {@link decide()} method returns + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} in case the AcceptOnMatch + * option value is set to true, if it is false then + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage varia + * @since 0.6 + */ +class LoggerLevelMatchFilter extends LoggerFilter { + + /** + * @var boolean + */ + var $acceptOnMatch = true; + + /** + * @var LoggerLevel + */ + var $levelToMatch; + + /** + * @return boolean + */ + function getAcceptOnMatch() + { + return $this->acceptOnMatch; + } + + /** + * @param boolean $acceptOnMatch + */ + function setAcceptOnMatch($acceptOnMatch) + { + $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true); + } + + /** + * @return LoggerLevel + */ + function getLevelToMatch() + { + return $this->levelToMatch; + } + + /** + * @param string $l the level to match + */ + function setLevelToMatch($l) + { + $this->levelToMatch = LoggerOptionConverter::toLevel($l, null); + } + + /** + * Return the decision of this filter. + * + * Returns {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} if the LevelToMatch + * option is not set or if there is not match. Otherwise, if there is a + * match, then the returned decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if the + * AcceptOnMatch property is set to true. The + * returned decision is {@link LOG4PHP_LOGGER_FILTER_DENY} if the + * AcceptOnMatch property is set to false. + * + * @param LoggerLoggingEvent $event + * @return integer + */ + function decide($event) + { + if($this->levelToMatch === null) + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + + if ($this->levelToMatch->equals($event->getLevel())) { + return $this->getAcceptOnMatch() ? + LOG4PHP_LOGGER_FILTER_ACCEPT : + LOG4PHP_LOGGER_FILTER_DENY; + } else { + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelRangeFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelRangeFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerLevelRangeFilter.php (revision 18220) @@ -0,0 +1,170 @@ +The filter admits three options LevelMin, LevelMax + * and AcceptOnMatch. + * + *If the level of the {@link LoggerLoggingEvent} is not between Min and Max + * (inclusive), then {@link LOG4PHP_LOGGER_FILTER_DENY} is returned.
+ * + *If the Logging event level is within the specified range, then if + * AcceptOnMatch is true, + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, and if + * AcceptOnMatch is false, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.
+ * + *If LevelMin is not defined, then there is no + * minimum acceptable level (i.e. a level is never rejected for + * being too "low"/unimportant). If LevelMax is not + * defined, then there is no maximum acceptable level (ie a + * level is never rejected for being too "high"/important).
+ * + *Refer to the {@link LoggerAppenderSkeleton::setThreshold()} method + * available to all appenders extending {@link LoggerAppenderSkeleton} + * for a more convenient way to filter out events by level.
+ * + * @log4j-class org.apache.log4j.varia.LevelRangeFilter + * @log4j-author Simon Kitching + * @log4j-author based on code by Ceki Gülcü + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage varia + * @since 0.6 + */ +class LoggerLevelRangeFilter extends LoggerFilter { + + /** + * @var boolean + */ + var $acceptOnMatch = true; + + /** + * @var LoggerLevel + */ + var $levelMin; + + /** + * @var LoggerLevel + */ + var $levelMax; + + /** + * @return boolean + */ + function getAcceptOnMatch() + { + return $this->acceptOnMatch; + } + + /** + * @param boolean $acceptOnMatch + */ + function setAcceptOnMatch($acceptOnMatch) + { + $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true); + } + + /** + * @return LoggerLevel + */ + function getLevelMin() + { + return $this->levelMin; + } + + /** + * @param string $l the level min to match + */ + function setLevelMin($l) + { + $this->levelMin = LoggerOptionConverter::toLevel($l, null); + } + + /** + * @return LoggerLevel + */ + function getLevelMax() + { + return $this->levelMax; + } + + /** + * @param string $l the level max to match + */ + function setLevelMax($l) + { + $this->levelMax = LoggerOptionConverter::toLevel($l, null); + } + + /** + * Return the decision of this filter. + * + * @param LoggerLoggingEvent $event + * @return integer + */ + function decide($event) + { + $level = $event->getLevel(); + + if($this->levelMin !== null) { + if ($level->isGreaterOrEqual($this->levelMin) == false) { + // level of event is less than minimum + return LOG4PHP_LOGGER_FILTER_DENY; + } + } + + if($this->levelMax !== null) { + if ($level->toInt() > $this->levelMax->toInt()) { + // level of event is greater than maximum + // Alas, there is no Level.isGreater method. and using + // a combo of isGreaterOrEqual && !Equal seems worse than + // checking the int values of the level objects.. + return LOG4PHP_LOGGER_FILTER_DENY; + } + } + + if ($this->getAcceptOnMatch()) { + // this filter set up to bypass later filters and always return + // accept if level in range + return LOG4PHP_LOGGER_FILTER_ACCEPT; + } else { + // event is ok for this filter; allow later filters to have a look.. + return LOG4PHP_LOGGER_FILTER_NEUTRAL; + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerDenyAllFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerDenyAllFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/varia/LoggerDenyAllFilter.php (revision 18220) @@ -0,0 +1,59 @@ +You can add this filter to the end of a filter chain to + * switch from the default "accept all unless instructed otherwise" + * filtering behaviour to a "deny all unless instructed otherwise" + * behaviour. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage varia + * @since 0.3 + */ +class LoggerDenyAllFilter extends LoggerFilter { + + /** + * Always returns the integer constant {@link LOG4PHP_LOGGER_FILTER_DENY} + * regardless of the {@link LoggerLoggingEvent} parameter. + * + * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to filter. + * @return LOG4PHP_LOGGER_FILTER_DENY Always returns {@link LOG4PHP_LOGGER_FILTER_DENY} + */ + function decide($event) + { + return LOG4PHP_LOGGER_FILTER_DENY; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternParser.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternParser.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternParser.php (revision 18220) @@ -0,0 +1,408 @@ +It is this class that parses conversion patterns and creates + * a chained list of {@link LoggerPatternConverter} converters. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage helpers + * + * @since 0.3 + */ +class LoggerPatternParser { + + var $state; + var $currentLiteral; + var $patternLength; + var $i; + + /** + * @var LoggerPatternConverter + */ + var $head = null; + + /** + * @var LoggerPatternConverter + */ + var $tail = null; + + /** + * @var LoggerFormattingInfo + */ + var $formattingInfo; + + /** + * @var string pattern to parse + */ + var $pattern; + + /** + * Constructor + * + * @param string $pattern + */ + function LoggerPatternParser($pattern) + { + LoggerLog::debug("LoggerPatternParser::LoggerPatternParser() pattern='$pattern'"); + + $this->pattern = $pattern; + $this->patternLength = strlen($pattern); + $this->formattingInfo = new LoggerFormattingInfo(); + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE; + } + + /** + * @param LoggerPatternConverter $pc + */ + function addToList($pc) + { + // LoggerLog::debug("LoggerPatternParser::addToList()"); + + if($this->head == null) { + $this->head = $pc; + $this->tail =& $this->head; + } else { + $this->tail->next = $pc; + $this->tail =& $this->tail->next; + } + } + + /** + * @return string + */ + function extractOption() + { + if(($this->i < $this->patternLength) and ($this->pattern{$this->i} == '{')) { + $end = strpos($this->pattern, '}' , $this->i); + if ($end !== false) { + $r = substr($this->pattern, ($this->i + 1), ($end - $this->i - 1)); + $this->i= $end + 1; + return $r; + } + } + return null; + } + + /** + * The option is expected to be in decimal and positive. In case of + * error, zero is returned. + */ + function extractPrecisionOption() + { + $opt = $this->extractOption(); + $r = 0; + if ($opt !== null) { + if (is_numeric($opt)) { + $r = (int)$opt; + if($r <= 0) { + LoggerLog::warn("Precision option ({$opt}) isn't a positive integer."); + $r = 0; + } + } else { + LoggerLog::warn("Category option \"{$opt}\" not a decimal integer."); + } + } + return $r; + } + + function parse() + { + LoggerLog::debug("LoggerPatternParser::parse()"); + + $c = ''; + $this->i = 0; + $this->currentLiteral = ''; + while ($this->i < $this->patternLength) { + $c = $this->pattern{$this->i++}; +// LoggerLog::debug("LoggerPatternParser::parse() char is now '$c' and currentLiteral is '{$this->currentLiteral}'"); + switch($this->state) { + case LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE: + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE'"); + // In literal state, the last char is always a literal. + if($this->i == $this->patternLength) { + $this->currentLiteral .= $c; + continue; + } + if($c == LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR) { + // LoggerLog::debug("LoggerPatternParser::parse() char is an escape char"); + // peek at the next char. + switch($this->pattern{$this->i}) { + case LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR: + // LoggerLog::debug("LoggerPatternParser::parse() next char is an escape char"); + $this->currentLiteral .= $c; + $this->i++; // move pointer + break; + case 'n': + // LoggerLog::debug("LoggerPatternParser::parse() next char is 'n'"); + $this->currentLiteral .= LOG4PHP_LINE_SEP; + $this->i++; // move pointer + break; + default: + if(strlen($this->currentLiteral) != 0) { + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); + LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\"."); + } + $this->currentLiteral = $c; + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE; + $this->formattingInfo->reset(); + } + } else { + $this->currentLiteral .= $c; + } + break; + case LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE: + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE'"); + $this->currentLiteral .= $c; + switch($c) { + case '-': + $this->formattingInfo->leftAlign = true; + break; + case '.': + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE; + break; + default: + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { + $this->formattingInfo->min = ord($c) - ord('0'); + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE; + } else { + $this->finalizeConverter($c); + } + } // switch + break; + case LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE: + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE'"); + $this->currentLiteral .= $c; + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { + $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0')); + } elseif ($c == '.') { + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE; + } else { + $this->finalizeConverter($c); + } + break; + case LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE: + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE'"); + $this->currentLiteral .= $c; + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { + $this->formattingInfo->max = ord($c) - ord('0'); + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE; + } else { + LoggerLog::warn("LoggerPatternParser::parse() Error occured in position {$this->i}. Was expecting digit, instead got char \"{$c}\"."); + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE; + } + break; + case LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE: + // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE'"); + $this->currentLiteral .= $c; + if(ord($c) >= ord('0') and ord($c) <= ord('9')) { + $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0')); + } else { + $this->finalizeConverter($c); + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE; + } + break; + } // switch + } // while + if(strlen($this->currentLiteral) != 0) { + $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral)); + // LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\"."); + } + return $this->head; + } + + function finalizeConverter($c) + { + LoggerLog::debug("LoggerPatternParser::finalizeConverter() with char '$c'"); + + $pc = null; + switch($c) { + case 'c': + $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption()); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() CATEGORY converter."); + $this->currentLiteral = ''; + break; + case 'C': + $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption()); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() CLASSNAME converter."); + $this->currentLiteral = ''; + break; + case 'd': + $dateFormatStr = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT; + $dOpt = $this->extractOption(); + + if($dOpt !== null) + $dateFormatStr = $dOpt; + + if ($dateFormatStr == 'ISO8601') { + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601; + } elseif($dateFormatStr == 'ABSOLUTE') { + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ABSOLUTE; + } elseif($dateFormatStr == 'DATE') { + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_DATE; + } else { + $df = $dateFormatStr; + if ($df == null) { + $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601; + } + } + $pc = new LoggerDatePatternConverter($this->formattingInfo, $df); + $this->currentLiteral = ''; + break; + case 'F': + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() File name converter."); + $this->currentLiteral = ''; + break; + case 'l': + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() Location converter."); + $this->currentLiteral = ''; + break; + case 'L': + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() LINE NUMBER converter."); + $this->currentLiteral = ''; + break; + case 'm': + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() MESSAGE converter."); + $this->currentLiteral = ''; + break; + case 'M': + $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER); + $this->currentLiteral = ''; + break; + case 'p': + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER); + $this->currentLiteral = ''; + break; + case 'r': + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() RELATIVE TIME converter."); + $this->currentLiteral = ''; + break; + case 't': + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() THREAD converter."); + $this->currentLiteral = ''; + break; + case 'u': + if($this->i < $this->patternLength) { + $cNext = $this->pattern{$this->i}; + if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) { + $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0'))); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() USER converter [{$cNext}]."); + $this->currentLiteral = ''; + $this->i++; + } else { + LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char '{$cNext}' at position {$this->i}."); + } + } + break; + case 'x': + $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() NDC converter."); + $this->currentLiteral = ''; + break; + + case 'X': + $xOpt = $this->extractOption(); + $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt); + LoggerLog::debug("LoggerPatternParser::finalizeConverter() MDC converter."); + $this->currentLiteral = ''; + break; + default: + LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char [$c] at position {$this->i} in conversion pattern."); + $pc = new LoggerLiteralPatternConverter($this->currentLiteral); + $this->currentLiteral = ''; + } + $this->addConverter($pc); + } + + function addConverter($pc) + { + $this->currentLiteral = ''; + // Add the pattern converter to the list. + $this->addToList($pc); + // Next pattern is assumed to be a literal. + $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE; + // Reset formatting info + $this->formattingInfo->reset(); + } +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerTransform.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerTransform.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerTransform.php (revision 18220) @@ -0,0 +1,95 @@ +'); +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END', ']]>'); +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END', + LOG4PHP_LOGGER_TRANSFORM_CDATA_END . + LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END . + LOG4PHP_LOGGER_TRANSFORM_CDATA_START +); + +/** + * Utility class for transforming strings. + * + * @author Marco Vassura + * @package log4php + * @subpackage helpers + * @since 0.7 + */ +class LoggerTransform { + + /** + * This method takes a string which may contain HTML tags (ie, + * <b>, <table>, etc) and replaces any '<' and '>' + * characters with respective predefined entity references. + * + * @param string $input The text to be converted. + * @return string The input string with the characters '<' and '>' replaced with + * < and > respectively. + * @static + */ + function escapeTags($input) + { + //Check if the string is null or zero length -- if so, return + //what was sent in. + + if(empty($input)) + return $input; + + //Use a StringBuffer in lieu of String concatenation -- it is + //much more efficient this way. + + return htmlspecialchars($input, ENT_NOQUOTES); + } + + /** + * Ensures that embeded CDEnd strings (]]>) are handled properly + * within message, NDC and throwable tag text. + * + * @param string $buf String holding the XML data to this point. The + * initial CDStart () + * of the CDATA section are the responsibility of + * the calling method. + * @param string &str The String that is inserted into an existing + * CDATA Section within buf. + * @static + */ + function appendEscapingCDATA(&$buf, $str) + { + if(empty($str)) + return; + + $rStr = str_replace( + LOG4PHP_LOGGER_TRANSFORM_CDATA_END, + LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END, + $str + ); + $buf .= $rStr; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerOptionConverter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerOptionConverter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerOptionConverter.php (revision 18220) @@ -0,0 +1,344 @@ +$key using this search criteria: + * - if $key is a constant then return it. Else + * - if $key is set in $_ENV then return it. Else + * - return $def. + * + * @param string $key The key to search for. + * @param string $def The default value to return. + * @return string the string value of the system property, or the default + * value if there is no property with that key. + * + * @static + */ + public static function getSystemProperty($key, $def) + { + LoggerLog::debug("LoggerOptionConverter::getSystemProperty():key=[{$key}]:def=[{$def}]."); + + if (defined($key)) { + return (string)constant($key); + } elseif (isset($_ENV[$key])) { + return (string)$_ENV[$key]; + } else { + return $def; + } + } + + /** + * If $value is true, then true is + * returned. If $value is false, then + * true is returned. Otherwise, $default is + * returned. + * + *Case of value is unimportant.
+ * + * @param string $value + * @param boolean $default + * @return boolean + * + * @static + */ + public static function toBoolean($value, $default) + { + if($value === null) + return $default; + if ($value == 1) + return true; + $trimmedVal = strtolower(trim($value)); + if ("true" == $trimmedVal or "yes" == $trimmedVal) + return true; + if ("false" == $trimmedVal) + return false; + return $default; + } + + /** + * @param string $value + * @param integer $default + * @return integer + * @static + */ + public static function toInt($value, $default) + { + $value = trim($value); + if (is_numeric($value)) { + return (int)$value; + } else { + return $default; + } + } + + /** + * Converts a standard or custom priority level to a Level + * object. + * + *If $value is of form "level#full_file_classname", + * where full_file_classname means the class filename with path + * but without php extension, then the specified class' toLevel() method + * is called to process the specified level string; if no '#' + * character is present, then the default {@link LoggerLevel} + * class is used to process the level value.
+ * + *As a special case, if the $value parameter is + * equal to the string "NULL", then the value null will + * be returned.
+ * + *If any error occurs while converting the value to a level, + * the $defaultValue parameter, which may be + * null, is returned.
+ * + *Case of $value is insignificant for the level level, but is + * significant for the class name part, if present.
+ * + * @param string $value + * @param LoggerLevel $defaultValue + * @return LoggerLevel a {@link LoggerLevel} or null + * @static + */ + public static function toLevel($value, $defaultValue) + { + if($value === null) + return $defaultValue; + + $hashIndex = strpos($value, '#'); + if ($hashIndex === false) { + if("NULL" == strtoupper($value)) { + return null; + } else { + // no class name specified : use standard Level class + return LoggerLevel::toLevel($value, $defaultValue); + } + } + + $result = $defaultValue; + + $clazz = substr($value, ($hashIndex + 1)); + $levelName = substr($value, 0, $hashIndex); + + // This is degenerate case but you never know. + if("NULL" == strtoupper($levelName)) { + return null; + } + + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}]:pri=[{$levelName}]"); + + if (!class_exists($clazz)) + @include_once("{$clazz}.php"); + + $clazz = basename($clazz); + + if (class_exists($clazz)) { + $result = @call_user_func(array($clazz, 'toLevel'), $levelName, $defaultValue); + if (!is_a($result, 'loggerlevel')) { + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}] cannot call toLevel(). Returning default."); + $result = $defaultValue; + } + } else { + LoggerLog::warn("LoggerOptionConverter::toLevel() class '{$clazz}' doesnt exists."); + } + return $result; + } + + /** + * @param string $value + * @param float $default + * @return float + * + * @static + */ + public static function toFileSize($value, $default) + { + if ($value === null) + return $default; + + $s = strtoupper(trim($value)); + $multiplier = (float)1; + if(($index = strpos($s, 'KB')) !== false) { + $multiplier = 1024; + $s = substr($s, 0, $index); + } elseif(($index = strpos($s, 'MB')) !== false) { + $multiplier = 1024 * 1024; + $s = substr($s, 0, $index); + } elseif(($index = strpos($s, 'GB')) !== false) { + $multiplier = 1024 * 1024 * 1024; + $s = substr($s, 0, $index); + } + if(is_numeric($s)) { + return (float)$s * $multiplier; + } else { + LoggerLog::warn("LoggerOptionConverter::toFileSize() [{$s}] is not in proper form."); + } + return $default; + } + + /** + * Find the value corresponding to $key in + * $props. Then perform variable substitution on the + * found value. + * + * @param string $key + * @param array $props + * @return string + * + * @static + */ + public static function findAndSubst($key, $props) + { + $value = @$props[$key]; + if(empty($value)) { + return null; + } + return LoggerOptionConverter::substVars($value, $props); + } + + /** + * Perform variable substitution in string $val from the + * values of keys found with the {@link getSystemProperty()} method. + * + *The variable substitution delimeters are ${ and }. + * + *
For example, if the "MY_CONSTANT" contains "value", then
+ * the call
+ *
+ * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}.");
+ *
+ * will set the variable $s to "Value of key is value.".
If no value could be found for the specified key, then the + * $props parameter is searched, if the value could not + * be found there, then substitution defaults to the empty string.
+ * + *For example, if {@link getSystemProperty()} cannot find any value for the key
+ * "inexistentKey", then the call
+ *
+ * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
+ *
+ * will set $s to "Value of inexistentKey is []".
A warn is thrown if $val contains a start delimeter "${" + * which is not balanced by a stop delimeter "}" and an empty string is returned.
+ * + * @log4j-author Avy Sharell + * + * @param string $val The string on which variable substitution is performed. + * @param array $props + * @return string + * + * @static + */ + public static function substVars($val, $props = null) + { + LoggerLog::debug("LoggerOptionConverter::substVars():val=[{$val}]"); + + $sbuf = ''; + $i = 0; + while(true) { + $j = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_START, $i); + if ($j === false) { + LoggerLog::debug("LoggerOptionConverter::substVars() no more variables"); + // no more variables + if ($i == 0) { // this is a simple string + LoggerLog::debug("LoggerOptionConverter::substVars() simple string"); + return $val; + } else { // add the tail string which contails no variables and return the result. + $sbuf .= substr($val, $i); + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]. Returning sbuf"); + return $sbuf; + } + } else { + + $sbuf .= substr($val, $i, $j-$i); + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]:i={$i}:j={$j}."); + $k = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_STOP, $j); + if ($k === false) { + LoggerLog::warn( + "LoggerOptionConverter::substVars() " . + "'{$val}' has no closing brace. Opening brace at position {$j}." + ); + return ''; + } else { + $j += LOG4PHP_OPTION_CONVERTER_DELIM_START_LEN; + $key = substr($val, $j, $k - $j); + // first try in System properties + $replacement = LoggerOptionConverter::getSystemProperty($key, null); + // then try props parameter + if($replacement == null and $props !== null) { + $replacement = @$props[$key]; + } + + if(!empty($replacement)) { + // Do variable substitution on the replacement string + // such that we can solve "Hello ${x2}" as "Hello p1" + // the where the properties are + // x1=p1 + // x2=${x1} + $recursiveReplacement = LoggerOptionConverter::substVars($replacement, $props); + $sbuf .= $recursiveReplacement; + } + $i = $k + LOG4PHP_OPTION_CONVERTER_DELIM_STOP_LEN; + } + } + } + } + +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternConverter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternConverter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerPatternConverter.php (revision 18220) @@ -0,0 +1,506 @@ +Conversion specifiers in a conversion patterns are parsed to + * individual PatternConverters. Each of which is responsible for + * converting a logging event in a converter specific manner. + * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + * @subpackage helpers + * @abstract + * @since 0.3 + */ +class LoggerPatternConverter { + + /** + * @var LoggerPatternConverter next converter in converter chain + */ + var $next = null; + + var $min = -1; + var $max = 0x7FFFFFFF; + var $leftAlign = false; + + /** + * Constructor + * + * @param LoggerFormattingInfo $fi + */ + function LoggerPatternConverter($fi = null) + { + if ($fi !== null) { + $this->min = $fi->min; + $this->max = $fi->max; + $this->leftAlign = $fi->leftAlign; + } + } + + /** + * Derived pattern converters must override this method in order to + * convert conversion specifiers in the correct way. + * + * @param LoggerLoggingEvent $event + */ + function convert($event) {} + + /** + * A template method for formatting in a converter specific way. + * + * @param string &$sbuf string buffer + * @param LoggerLoggingEvent $e + */ + function format(&$sbuf, $e) + { + LoggerLog::debug("LoggerPatternConverter::format() sbuf='$sbuf'"); + + $s = $this->convert($e); + + LoggerLog::debug("LoggerPatternConverter::format() converted event is '$s'"); + + + if($s == null or empty($s)) { + if(0 < $this->min) + $this->spacePad($sbuf, $this->min); + return; + } + + $len = strlen($s); + + if($len > $this->max) { + $sbuf .= substr($s , 0, ($len - $this->max)); + } elseif($len < $this->min) { + if($this->leftAlign) { + $sbuf .= $s; + $this->spacePad($sbuf, ($this->min - $len)); + } else { + $this->spacePad($sbuf, ($this->min - $len)); + $sbuf .= $s; + } + } else { + $sbuf .= $s; + } + } + + + /** + * Fast space padding method. + * + * @param string &$sbuf string buffer + * @param integer $length pad length + * + * @todo reimplement using PHP string functions + */ + function spacePad(&$sbuf, $length) + { + LoggerLog::debug("LoggerPatternConverter::spacePad() sbuf='$sbuf' len='$length'"); + + while($length >= 32) { + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][5]; + $length -= 32; + } + + for($i = 4; $i >= 0; $i--) { + if(($length & (1<<$i)) != 0) { + $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][$i]; + } + } + + // $sbuf = str_pad($sbuf, $length); + } +} + +// --------------------------------------------------------------------- +// PatternConverters +// --------------------------------------------------------------------- + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerBasicPatternConverter extends LoggerPatternConverter { + + /** + * @var integer + */ + var $type; + + /** + * Constructor + * + * @param string $formattingInfo + * @param integer $type + */ + function LoggerBasicPatternConverter($formattingInfo, $type) + { + LoggerLog::debug("LoggerBasicPatternConverter::LoggerBasicPatternConverter() type='$type'"); + + $this->LoggerPatternConverter($formattingInfo); + $this->type = $type; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + switch($this->type) { + case LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER: + $timeStamp = $event->getTimeStamp(); + $startTime = LoggerLoggingEvent::getStartTime(); + return (string)(int)($timeStamp * 1000 - $startTime * 1000); + + case LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER: + return $event->getThreadName(); + + case LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER: + $level = $event->getLevel(); + return $level->toString(); + + case LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER: + return $event->getNDC(); + + case LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER: + return $event->getRenderedMessage(); + + default: + return ''; + } + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerLiteralPatternConverter extends LoggerPatternConverter { + + /** + * @var string + */ + var $literal; + + /** + * Constructor + * + * @param string $value + */ + function LoggerLiteralPatternConverter($value) + { + LoggerLog::debug("LoggerLiteralPatternConverter::LoggerLiteralPatternConverter() value='$value'"); + + $this->literal = $value; + } + + /** + * @param string &$sbuf + * @param LoggerLoggingEvent $event + */ + function format(&$sbuf, $event) + { + $sbuf .= $this->literal; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + return $this->literal; + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerDatePatternConverter extends LoggerPatternConverter { + + /** + * @var string + */ + var $df; + + /** + * Constructor + * + * @param string $formattingInfo + * @param string $df + */ + function LoggerDatePatternConverter($formattingInfo, $df) + { + LoggerLog::debug("LoggerDatePatternConverter::LoggerDatePatternConverter() dateFormat='$df'"); + + $this->LoggerPatternConverter($formattingInfo); + $this->df = $df; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + $timeStamp = $event->getTimeStamp(); + $usecs = round(($timeStamp - (int)$timeStamp) * 1000); + $this->df = preg_replace('/((?df); + + return date($this->df, $event->getTimeStamp()); + + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerMDCPatternConverter extends LoggerPatternConverter { + + /** + * @var string + */ + var $key; + + /** + * Constructor + * + * @param string $formattingInfo + * @param string $key + */ + function LoggerMDCPatternConverter($formattingInfo, $key) + { + LoggerLog::debug("LoggerMDCPatternConverter::LoggerMDCPatternConverter() key='$key'"); + + $this->LoggerPatternConverter($formattingInfo); + $this->key = $key; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + return $event->getMDC($this->key); + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerLocationPatternConverter extends LoggerPatternConverter { + + /** + * @var integer + */ + var $type; + + /** + * Constructor + * + * @param string $formattingInfo + * @param integer $type + */ + function LoggerLocationPatternConverter($formattingInfo, $type) + { + LoggerLog::debug("LoggerLocationPatternConverter::LoggerLocationPatternConverter() type='$type'"); + + $this->LoggerPatternConverter($formattingInfo); + $this->type = $type; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + $locationInfo = $event->getLocationInformation(); + switch($this->type) { + case LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER: + return $locationInfo->getFullInfo(); + case LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER: + return $locationInfo->getMethodName(); + case LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER: + return $locationInfo->getLineNumber(); + case LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER: + return $locationInfo->getFileName(); + default: + return ''; + } + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + * @abstract + */ +class LoggerNamedPatternConverter extends LoggerPatternConverter { + + /** + * @var integer + */ + var $precision; + + /** + * Constructor + * + * @param string $formattingInfo + * @param integer $precision + */ + function LoggerNamedPatternConverter($formattingInfo, $precision) + { + LoggerLog::debug("LoggerNamedPatternConverter::LoggerNamedPatternConverter() precision='$precision'"); + + $this->LoggerPatternConverter($formattingInfo); + $this->precision = $precision; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + * @abstract + */ + function getFullyQualifiedName($event) + { + // abstract + return; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function convert($event) + { + $n = $this->getFullyQualifiedName($event); + if ($this->precision <= 0) { + return $n; + } else { + $len = strlen($n); + + // We substract 1 from 'len' when assigning to 'end' to avoid out of + // bounds exception in return r.substring(end+1, len). This can happen if + // precision is 1 and the category name ends with a dot. + $end = $len -1 ; + for($i = $this->precision; $i > 0; $i--) { + $end = strrpos(substr($n, 0, ($end - 1)), '.'); + if ($end == false) + return $n; + } + return substr($n, ($end + 1), $len); + } + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerClassNamePatternConverter extends LoggerNamedPatternConverter { + + /** + * Constructor + * + * @param string $formattingInfo + * @param integer $precision + */ + function LoggerClassNamePatternConverter($formattingInfo, $precision) + { + LoggerLog::debug("LoggerClassNamePatternConverter::LoggerClassNamePatternConverter() precision='$precision'"); + + $this->LoggerNamedPatternConverter($formattingInfo, $precision); + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function getFullyQualifiedName($event) + { + return $event->fqcn; + } +} + +/** + * @author Marco Vassura + * @package log4php + * @subpackage helpers + */ +class LoggerCategoryPatternConverter extends LoggerNamedPatternConverter { + + /** + * Constructor + * + * @param string $formattingInfo + * @param integer $precision + */ + function LoggerCategoryPatternConverter($formattingInfo, $precision) + { + LoggerLog::debug("LoggerCategoryPatternConverter::LoggerCategoryPatternConverter() precision='$precision'"); + + $this->LoggerNamedPatternConverter($formattingInfo, $precision); + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function getFullyQualifiedName($event) + { + return $event->getLoggerName(); + } +} + Index: branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerFormattingInfo.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerFormattingInfo.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/helpers/LoggerFormattingInfo.php (revision 18220) @@ -0,0 +1,63 @@ +min = -1; + $this->max = 0x7FFFFFFF; + $this->leftAlign = false; + } + + function dump() + { + LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}"); + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLayout.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLayout.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerLayout.php (revision 18220) @@ -0,0 +1,96 @@ +getRenderedMessage(); + } + + /** + * Returns the content type output by this layout. + * @return string + */ + public function getContentType() + { + return "text/plain"; + } + + /** + * Returns the footer for the layout format. + * @return string + */ + public function getFooter() + { + return null; + } + + /** + * Returns the header for the layout format. + * @return string + */ + public function getHeader() + { + return null; + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/LoggerHierarchy.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/LoggerHierarchy.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/LoggerHierarchy.php (revision 18220) @@ -0,0 +1,372 @@ +The casual user does not have to deal with this class directly. + * + *The structure of the logger hierarchy is maintained by the + * getLogger method. The hierarchy is such that children link + * to their parent but parents do not have any pointers to their + * children. Moreover, loggers can be instantiated in any order, in + * particular descendant before ancestor.
+ * + *In case a descendant is created before a particular ancestor, + * then it creates a provision node for the ancestor and adds itself + * to the provision node. Other descendants of the same ancestor add + * themselves to the previously created provision node.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + */ +class LoggerHierarchy { + + /** + * @var object currently unused + */ + protected $defaultFactory; + + /** + * @var boolean activate internal logging + * @see LoggerLog + */ + public $debug = false; + + /** + * @var array hierarchy tree. saves here all loggers + */ + protected $ht = array(); + + /** + * @var LoggerRoot + */ + protected $root = null; + + /** + * @var LoggerRendererMap + */ + protected $rendererMap; + + /** + * @var LoggerLevel main level threshold + */ + protected $threshold; + + /** + * @var boolean currently unused + */ + protected $emittedNoAppenderWarning = false; + + /** + * @var boolean currently unused + */ + protected $emittedNoResourceBundleWarning = false; + + public static function singleton() + { + static $instance; + + if (!isset($instance)) + $instance = new LoggerHierarchy(new LoggerRoot()); + return $instance; + } + + /** + * Create a new logger hierarchy. + * @param object $root the root logger + */ + protected function __construct($root) + { + $this->root = $root; + // Enable all level levels by default. + $this->setThreshold(LoggerLevel::getLevelAll()); + $this->root->setHierarchy($this); + $this->rendererMap = new LoggerRendererMap(); + $this->defaultFactory = new LoggerDefaultCategoryFactory(); + } + + /** + * Add a HierarchyEventListener event to the repository. + * Not Yet Impl. + */ + public function addHierarchyEventListener($listener) + { + return; + } + + /** + * Add an object renderer for a specific class. + * @param string $classToRender + * @param LoggerObjectRenderer $or + */ + public function addRenderer($classToRender, $or) + { + $this->rendererMap->put($classToRender, $or); + } + + /** + * This call will clear all logger definitions from the internal hashtable. + */ + public function clear() + { + $this->ht = array(); + } + + public function emitNoAppenderWarning($cat) + { + return; + } + + /** + * Check if the named logger exists in the hierarchy. + * @param string $name + * @return boolean + */ + public function exists($name) + { + return isset($this->ht[$name]); + } + + /** + * Not Implemented. + * @param Logger $logger + * @param LoggerAppender $appender + */ + public function fireAddAppenderEvent($logger, $appender) + { + return; + } + + /** + * @deprecated Please use {@link getCurrentLoggers()} instead. + */ + public function getCurrentCategories() + { + return $this->getCurrentLoggers(); + } + + /** + * Returns all the currently defined categories in this hierarchy as an array. + * @return array + */ + public function getCurrentLoggers() + { + return array_values($this->ht); + } + + /** + * Return a new logger instance named as the first parameter using the default factory. + * + * @param string $name logger name + * @param LoggerFactory $factory a {@link LoggerFactory} instance or null + * @return Logger + */ + public function getLogger($name, $factory = null) + { + if ($factory === null) { + return $this->getLoggerByFactory($name, $this->defaultFactory); + } else { + return $this->getLoggerByFactory($name, $factory); + } + } + + /** + * Return a new logger instance named as the first parameter using the default factory. + * + * @param string $name logger name + * @return Logger + * @todo merge with {@link getLogger()} + */ + public function getLoggerByFactory($name, $factory) + { + if (!isset($this->ht[$name])) { + $this->ht[$name] = $factory->makeNewLoggerInstance($name); + $this->ht[$name]->setHierarchy($this); + $nodes = explode('.', $name); + $firstNode = array_shift($nodes); + if ( $firstNode != $name and isset($this->ht[$firstNode])) { + $this->ht[$name]->setParent($this->ht[$firstNode]); + } else { + $this->ht[$name]->setParent($this->root); + } + if (sizeof($nodes) > 0) { + // find parent node + foreach ($nodes as $node) { + $parentNode = "$firstNode.$node"; + if (isset($this->ht[$parentNode]) and $parentNode != $name) { + $this->ht[$name]->setParent($this->ht[$parentNode]); + } + $firstNode .= ".$node"; + } + } + } + return $this->ht[$name]; + } + + /** + * @return LoggerRendererMap Get the renderer map for this hierarchy. + */ + public function getRendererMap() + { + return $this->rendererMap; + } + + /** + * @return LoggerRoot Get the root of this hierarchy. + */ + public function getRootLogger() + { + if (!isset($this->root) or $this->root == null) + $this->root = new LoggerRoot(); + return $this->root; + } + + /** + * @return LoggerLevel Returns the threshold Level. + */ + public function getThreshold() + { + return $this->threshold; + } + + /** + * This method will return true if this repository is disabled + * for level object passed as parameter and false otherwise. + * @return boolean + */ + public function isDisabled($level) + { + return ($this->threshold->level > $level->level); + } + + /** + * @deprecated Deprecated with no replacement. + */ + public function overrideAsNeeded($override) + { + return; + } + + /** + * Reset all values contained in this hierarchy instance to their + * default. + * + * This removes all appenders from all categories, sets + * the level of all non-root categories to null, + * sets their additivity flag to true and sets the level + * of the root logger to {@link LOGGER_LEVEL_DEBUG}. Moreover, + * message disabling is set its default "off" value. + * + *Existing categories are not removed. They are just reset. + * + *
This method should be used sparingly and with care as it will + * block all logging until it is completed.
+ */ + public function resetConfiguration() + { + $root = $this->getRootLogger(); + + $root->setLevel(LoggerLevel::getLevelDebug()); + $this->setThreshold(LoggerLevel::getLevelAll()); + $this->shutDown(); + $loggers = $this->getCurrentLoggers(); + $enumLoggers = sizeof($loggers); + for ($i = 0; $i < $enumLoggers; $i++) { + $loggers[$i]->setLevel(null); + $loggers[$i]->setAdditivity(true); + $loggers[$i]->setResourceBundle(null); + $loggers[$i]->removeAllAppenders(); + } + $this->rendererMap->clear(); + } + + /** + * @deprecated Deprecated with no replacement. + */ + public function setDisableOverride($override) + { + return; + } + + /** + * Used by subclasses to add a renderer to the hierarchy passed as parameter. + * @param string $renderedClass a LoggerRenderer class name + * @param LoggerRenderer $renderer + * + */ + public function setRenderer($renderedClass, $renderer) + { + $this->rendererMap->put($renderedClass, $renderer); + } + + /** + * set a new threshold level + * + * @param LoggerLevel $l + */ + public function setThreshold($l) + { + if ($l !== null) + $this->threshold = $l; + } + + /** + * Shutting down a hierarchy will safely close and remove + * all appenders in all categories including the root logger. + * + *Some appenders such as {@link LoggerSocketAppender} + * need to be closed before the + * application exists. Otherwise, pending logging events might be + * lost. + * + *
The shutdown method is careful to close nested
+ * appenders before closing regular appenders. This is allows
+ * configurations where a regular appender is attached to a logger
+ * and again to a nested appender.
+ */
+ public function shutdown()
+ {
+ $this->root->removeAllAppenders();
+ $cats = $this->getCurrentLoggers();
+ $enumCats = sizeof($cats);
+ if ($enumCats > 0) {
+ for ($i = 0; $i < $enumCats; $i++) {
+ $cats[$i]->removeAllAppenders();
+ }
+ }
+ }
+}
Index: branches/comu-ver2/data/module/log4php/php5/log4php/Logger.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php5/log4php/Logger.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php5/log4php/Logger.php (revision 18220)
@@ -0,0 +1,599 @@
+name = $name;
+ }
+
+ /**
+ * Add a new Appender to the list of appenders of this Category instance.
+ *
+ * @param LoggerAppender $newAppender
+ */
+ public function addAppender($newAppender)
+ {
+ $appenderName = $newAppender->getName();
+ $this->aai[$appenderName] = $newAppender;
+ }
+
+ /**
+ * If assertion parameter is false, then logs msg as an error statement.
+ *
+ * @param bool $assertion
+ * @param string $msg message to log
+ */
+ public function assertLog($assertion = true, $msg = '')
+ {
+ if ($assertion == false) {
+ $this->error($msg);
+ }
+ }
+
+ /**
+ * Call the appenders in the hierarchy starting at this.
+ *
+ * @param LoggerLoggingEvent $event
+ */
+ public function callAppenders($event)
+ {
+ if (sizeof($this->aai) > 0) {
+ foreach (array_keys($this->aai) as $appenderName) {
+ $this->aai[$appenderName]->doAppend($event);
+ }
+ }
+ if ($this->parent != null and $this->getAdditivity()) {
+ $this->parent->callAppenders($event);
+ }
+ }
+
+ /**
+ * Log a message object with the DEBUG level including the caller.
+ *
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function debug($message, $caller = null)
+ {
+ $debugLevel = LoggerLevel::getLevelDebug();
+ if ($this->repository->isDisabled($debugLevel)) {
+ return;
+ }
+ if ($debugLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $debugLevel, $message);
+ }
+ }
+
+ /**
+ * Log a message object with the ERROR level including the caller.
+ *
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function error($message, $caller = null)
+ {
+ $errorLevel = LoggerLevel::getLevelError();
+ if ($this->repository->isDisabled($errorLevel)) {
+ return;
+ }
+ if ($errorLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $errorLevel, $message);
+ }
+ }
+
+ /**
+ * Deprecated. Please use LoggerManager::exists() instead.
+ *
+ * @param string $name
+ * @see LoggerManager::exists()
+ * @deprecated
+ */
+ public function exists($name)
+ {
+ return LoggerManager::exists($name);
+ }
+
+ /**
+ * Log a message object with the FATAL level including the caller.
+ *
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function fatal($message, $caller = null)
+ {
+ $fatalLevel = LoggerLevel::getLevelFatal();
+ if ($this->repository->isDisabled($fatalLevel)) {
+ return;
+ }
+ if ($fatalLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $fatalLevel, $message);
+ }
+ }
+
+ /**
+ * This method creates a new logging event and logs the event without further checks.
+ *
+ * It should not be called directly. Use {@link info()}, {@link debug()}, {@link warn()},
+ * {@link error()} and {@link fatal()} wrappers.
+ *
+ * @param string $fqcn Fully Qualified Class Name of the Logger
+ * @param mixed $caller caller object or caller string id
+ * @param LoggerLevel $level log level
+ * @param mixed $message message
+ * @see LoggerLoggingEvent
+ */
+ public function forcedLog($fqcn, $caller, $level, $message)
+ {
+ // $fqcn = is_object($caller) ? get_class($caller) : (string)$caller;
+ $this->callAppenders(new LoggerLoggingEvent($fqcn, $this, $level, $message));
+ }
+
+ /**
+ * Get the additivity flag for this Category instance.
+ * @return boolean
+ */
+ public function getAdditivity()
+ {
+ return $this->additive;
+ }
+
+ /**
+ * Get the appenders contained in this category as an array.
+ * @return array collection of appenders
+ */
+ public function getAllAppenders()
+ {
+ return array_values($this->aai);
+ }
+
+ /**
+ * Look for the appender named as name.
+ * @return LoggerAppender
+ */
+ public function getAppender($name)
+ {
+ return $this->aai[$name];
+ }
+
+ /**
+ * Please use the {@link getEffectiveLevel()} method instead.
+ * @deprecated
+ */
+ public function getChainedPriority()
+ {
+ return $this->getEffectiveLevel();
+ }
+
+ /**
+ * Please use {@link LoggerManager::getCurrentLoggers()} instead.
+ * @deprecated
+ */
+ public function getCurrentCategories()
+ {
+ return LoggerManager::getCurrentLoggers();
+ }
+
+ /**
+ * Please use {@link LoggerManager::getLoggerRepository()} instead.
+ * @deprecated
+ */
+ public function getDefaultHierarchy()
+ {
+ return LoggerManager::getLoggerRepository();
+ }
+
+ /**
+ * @deprecated Use {@link getLoggerRepository()}
+ * @return LoggerHierarchy
+ */
+ public function getHierarchy()
+ {
+ return $this->getLoggerRepository();
+ }
+
+ /**
+ * Starting from this category, search the category hierarchy for a non-null level and return it.
+ * @see LoggerLevel
+ * @return LoggerLevel or null
+ */
+ public function getEffectiveLevel()
+ {
+ for($c = $this; $c != null; $c = $c->parent) {
+ if($c->getLevel() !== null)
+ return $c->getLevel();
+ }
+ return null;
+ }
+
+ /**
+ * Retrieve a category with named as the name parameter.
+ * @return Logger
+ */
+ public function getInstance($name)
+ {
+ return LoggerManager::getLogger($name);
+ }
+
+ /**
+ * Returns the assigned Level, if any, for this Category.
+ * @return LoggerLevel or null
+ */
+ public function getLevel()
+ {
+ return $this->level;
+ }
+
+ /**
+ * Get a Logger by name (Delegate to {@link LoggerManager})
+ * @param string $name logger name
+ * @param LoggerFactory $factory a {@link LoggerFactory} instance or null
+ * @return Logger
+ * @static
+ */
+ public function getLogger($name, $factory = null)
+ {
+ return LoggerManager::getLogger($name, $factory);
+ }
+
+ /**
+ * Return the the repository where this Category is attached.
+ * @return LoggerHierarchy
+ */
+ public function getLoggerRepository()
+ {
+ return $this->repository;
+ }
+
+ /**
+ * Return the category name.
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Returns the parent of this category.
+ * @return Logger
+ */
+ public function getParent()
+ {
+ return $this->parent;
+ }
+
+ /**
+ * Please use getLevel() instead.
+ * @deprecated
+ */
+ public function getPriority()
+ {
+ return $this->getLevel();
+ }
+
+ /**
+ * Return the inherited ResourceBundle for this category.
+ */
+ public function getResourceBundle()
+ {
+ return;
+ }
+
+ /**
+ * Returns the string resource corresponding to key in this category's inherited resource bundle.
+ */
+ public function getResourceBundleString($key)
+ {
+ return;
+ }
+
+ /**
+ * Return the root of the default category hierarchy.
+ * @return LoggerRoot
+ */
+ public function getRoot()
+ {
+ return LoggerManager::getRootLogger();
+ }
+
+ /**
+ * get the Root Logger (Delegate to {@link LoggerManager})
+ * @return LoggerRoot
+ * @static
+ */
+ public function getRootLogger()
+ {
+ return LoggerManager::getRootLogger();
+ }
+
+ /**
+ * Log a message object with the INFO Level.
+ *
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function info($message, $caller = null)
+ {
+ $infoLevel = LoggerLevel::getLevelInfo();
+ if ($this->repository->isDisabled($infoLevel)) {
+ return;
+ }
+ if ($infoLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $infoLevel, $message);
+ }
+ }
+
+ /**
+ * Is the appender passed as parameter attached to this category?
+ *
+ * @param LoggerAppender $appender
+ */
+ public function isAttached($appender)
+ {
+ return isset($this->aai[$appender->getName()]);
+ }
+
+ /**
+ * Check whether this category is enabled for the DEBUG Level.
+ * @return boolean
+ */
+ public function isDebugEnabled()
+ {
+ $debugLevel = LoggerLevel::getLevelDebug();
+ if ($this->repository->isDisabled($debugLevel)) {
+ return false;
+ }
+ return ($debugLevel->isGreaterOrEqual($this->getEffectiveLevel()));
+ }
+
+ /**
+ * Check whether this category is enabled for a given Level passed as parameter.
+ *
+ * @param LoggerLevel level
+ * @return boolean
+ */
+ public function isEnabledFor($level)
+ {
+ if ($this->repository->isDisabled($level)) {
+ return false;
+ }
+ return (bool)($level->isGreaterOrEqual($this->getEffectiveLevel()));
+ }
+
+ /**
+ * Check whether this category is enabled for the info Level.
+ * @return boolean
+ * @see LoggerLevel
+ */
+ public function isInfoEnabled()
+ {
+ $infoLevel = LoggerLevel::getLevelInfo();
+ if ($this->repository->isDisabled($infoLevel)) {
+ return false;
+ }
+ return ($infoLevel->isGreaterOrEqual($this->getEffectiveLevel()));
+ }
+
+ /**
+ * Log a localized and parameterized message.
+ */
+ public function l7dlog($priority, $key, $params, $t)
+ {
+ return;
+ }
+
+ /**
+ * This generic form is intended to be used by wrappers.
+ *
+ * @param LoggerLevel $priority a valid level
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function log($priority, $message, $caller = null)
+ {
+ if ($this->repository->isDisabled($priority)) {
+ return;
+ }
+ if ($priority->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $priority, $message);
+ }
+ }
+
+ /**
+ * Remove all previously added appenders from this Category instance.
+ */
+ public function removeAllAppenders()
+ {
+ $appenderNames = array_keys($this->aai);
+ $enumAppenders = sizeof($appenderNames);
+ for ($i = 0; $i < $enumAppenders; $i++) {
+ $this->removeAppender($appenderNames[$i]);
+ }
+ }
+
+ /**
+ * Remove the appender passed as parameter form the list of appenders.
+ *
+ * @param mixed $appender can be an appender name or a {@link LoggerAppender} object
+ */
+ public function removeAppender($appender)
+ {
+ if ($appender instanceof LoggerAppender) {
+ $appender->close();
+ unset($this->aai[$appender->getName()]);
+ } elseif (is_string($appender) and isset($this->aai[$appender])) {
+ $this->aai[$appender]->close();
+ unset($this->aai[$appender]);
+ }
+ }
+
+ /**
+ * Set the additivity flag for this Category instance.
+ *
+ * @param boolean $additive
+ */
+ public function setAdditivity($additive)
+ {
+ $this->additive = (bool)$additive;
+ }
+
+ /**
+ * @deprecated Please use {@link setLevel()} instead.
+ * @see setLevel()
+ */
+ public function setPriority($priority)
+ {
+ $this->setLevel($priority);
+ }
+
+ /**
+ * Only the Hierarchy class can set the hierarchy of a
+ * category.
+ *
+ * @param LoggerHierarchy $repository
+ */
+ public function setHierarchy($repository)
+ {
+ $this->repository = $repository;
+ }
+
+ /**
+ * Set the level of this Category.
+ *
+ * @param LoggerLevel $level a level string or a level constant
+ */
+ public function setLevel($level)
+ {
+ $this->level = $level;
+ }
+
+ public function setParent($logger) {
+ if ($logger instanceof Logger) {
+ $this->parent = $logger;
+ }
+ }
+
+ /**
+ * Set the resource bundle to be used with localized logging methods
+ */
+ public function setResourceBundle($bundle)
+ {
+ return;
+ }
+
+ /**
+ * @deprecated use {@link LoggerManager::shutdown()} instead.
+ * @see LoggerManager::shutdown()
+ */
+ public function shutdown()
+ {
+ LoggerManager::shutdown();
+ }
+
+ /**
+ * Log a message with the WARN level.
+ *
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function warn($message, $caller = null)
+ {
+ $warnLevel = LoggerLevel::getLevelWarn();
+ if ($this->repository->isDisabled($warnLevel)) {
+ return;
+ }
+ if ($warnLevel->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $warnLevel, $message);
+ }
+ }
+
+}
Index: branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertySetter.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertySetter.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertySetter.php (revision 18220)
@@ -0,0 +1,163 @@
+
+ * $ps = new LoggerPropertySetter($anObject);
+ * $ps->set("name", "Joe");
+ * $ps->set("age", 32);
+ * $ps->set("isMale", true);
+ *
+ * will cause the invocations
+ *
+ * $anObject->setName("Joe");
+ * $anObject->setAge(32);
+ * $anObject->setMale(true)
+ *
+ * if such methods exist.
+ *
+ * @author Marco Vassura
+ * @version $Revision: 663201 $
+ * @package log4php
+ * @subpackage config
+ * @since 0.5
+ */
+class LoggerPropertySetter {
+
+ /**
+ * @var object the target object
+ * @access private
+ */
+ var $obj;
+
+ /**
+ * Create a new LoggerPropertySetter for the specified Object.
+ * This is done in prepartion for invoking {@link setProperty()}
+ * one or more times.
+ * @param object &$obj the object for which to set properties
+ */
+ function LoggerPropertySetter(&$obj)
+ {
+ $this->obj =& $obj;
+ }
+
+ /**
+ * Set the properties of an object passed as a parameter in one
+ * go. The properties
are parsed relative to a
+ * prefix
.
+ *
+ * @param object &$obj The object to configure.
+ * @param array $properties An array containing keys and values.
+ * @param string $prefix Only keys having the specified prefix will be set.
+ * @static
+ */
+ public static function setPropertiesByObject(&$obj, $properties, $prefix)
+ {
+ $pSetter = new LoggerPropertySetter($obj);
+ return $pSetter->setProperties($properties, $prefix);
+ }
+
+
+ /**
+ * Set the properites for the object that match the
+ * prefix
passed as parameter.
+ *
+ * @param array $properties An array containing keys and values.
+ * @param string $prefix Only keys having the specified prefix will be set.
+ */
+ function setProperties($properties, $prefix)
+ {
+ LoggerLog::debug("LoggerOptionConverter::setProperties():prefix=[{$prefix}]");
+
+ $len = strlen($prefix);
+ while (list($key,) = each($properties)) {
+ if (strpos($key, $prefix) === 0) {
+ if (strpos($key, '.', ($len + 1)) > 0)
+ continue;
+ $value = LoggerOptionConverter::findAndSubst($key, $properties);
+ $key = substr($key, $len);
+ if ($key == 'layout' and ($this->obj instanceof LoggerAppender)) {
+ continue;
+ }
+ $this->setProperty($key, $value);
+ }
+ }
+ $this->activate();
+ }
+
+ /**
+ * Set a property on this PropertySetter's Object. If successful, this
+ * method will invoke a setter method on the underlying Object. The
+ * setter is the one for the specified property name and the value is
+ * determined partly from the setter argument type and partly from the
+ * value specified in the call to this method.
+ *
+ *
If the setter expects a String no conversion is necessary. + * If it expects an int, then an attempt is made to convert 'value' + * to an int using new Integer(value). If the setter expects a boolean, + * the conversion is by new Boolean(value). + * + * @param string $name name of the property + * @param string $value String value of the property + */ + function setProperty($name, $value) + { + LoggerLog::debug("LoggerOptionConverter::setProperty():name=[{$name}]:value=[{$value}]"); + + if ($value === null) return; + + $method = "set" . ucfirst($name); + + if (!method_exists($this->obj, $method)) { + LoggerLog::warn( + "LoggerOptionConverter::setProperty() No such setter method for [{$name}] property in " . + get_class($this->obj) . "." + ); + } else { + return call_user_func(array(&$this->obj, $method), $value); + } + } + + function activate() + { + LoggerLog::debug("LoggerOptionConverter::activate()"); + + if (method_exists($this->obj, 'activateoptions')) { + return call_user_func(array(&$this->obj, 'activateoptions')); + } else { + LoggerLog::debug("LoggerOptionConverter::activate() Nothing to activate."); + } + } +} Index: branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertyGetter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertyGetter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php5/log4php/config/LoggerPropertyGetter.php (revision 18220) @@ -0,0 +1,39 @@ +It uses php {@link PHP_MANUAL#trigger_error trigger_error()} function + * to output messages.
+ *You need to recode methods to output messages in a different way.
+ * + * @author Marco Vassura + * @version $Revision: 635069 $ + * @package log4php + */ +class LoggerLog { + + protected static $debug = false; + + /** + * Log if debug is enabled. + * + * Log using php {@link PHP_MANUAL#trigger_error trigger_error()} function + * with E_USER_NOTICE level by default. + * + * @param string $message log message + * @param integer $errLevel level to log + * @static + */ + public static function log($message, $errLevel = E_USER_NOTICE) + { + if (LoggerLog::internalDebugging()) + trigger_error($message, $errLevel); + } + + public static function internalDebugging($value = null) + { + if (is_bool($value)) + self::$debug = $value; + return self::$debug; + } + + /** + * Report a debug message. + * + * @param string $message log message + * @static + * @since 0.3 + */ + public static function debug($message) + { + LoggerLog::log($message, E_USER_NOTICE); + } + + /** + * Report an error message. + * + * @param string $message log message + * @static + * @since 0.3 + */ + public static function error($message) + { + trigger_error($message, E_USER_ERROR); + } + + /** + * Report a warning message. + * + * @param string $message log message + * @static + * @since 0.3 + */ + public static function warn($message) + { + trigger_error($message, E_USER_WARNING); + } + +} Index: branches/comu-ver2/data/module/log4php/php4/log4php/LoggerLevel.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/LoggerLevel.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/LoggerLevel.php (revision 18220) @@ -0,0 +1,264 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details). + *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @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 + * OFF, FATAL, ERROR, + * WARN, INFODEBUG and + * ALL. + * + *The LoggerLevel class may be subclassed to define a larger + * level set.
+ * + * @author VxRYou should think twice before overriding the default + * implementation of isGreaterOrEqual 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; + } + } + } + } +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/LoggerPropertyConfigurator.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/LoggerPropertyConfigurator.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/LoggerPropertyConfigurator.php (revision 18220) @@ -0,0 +1,648 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php'); +require_once(LOG4PHP_DIR . '/config/LoggerPropertySetter.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/LoggerAppender.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php'); +require_once(LOG4PHP_DIR . '/LoggerManager.php'); + +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX', "log4php.category."); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX', "log4php.logger."); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX', "log4php.factory"); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX', "log4php.additivity."); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX', "log4php.rootCategory"); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX', "log4php.rootLogger"); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX', "log4php.appender."); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX', "log4php.renderer."); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX', "log4php.threshold"); + +/** + * Key for specifying the {@link LoggerFactory}. + */ +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY', "log4php.loggerFactory"); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY', "log4php.debug"); +define('LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME', "root"); + + + +/** + * Allows the configuration of log4php from an external file. + * + * See {@link doConfigure()} for the expected format. + * + *It is sometimes useful to see how log4php is reading configuration + * files. You can enable log4php internal logging by defining the + * log4php.debug variable.
+ * + *The LoggerPropertyConfigurator does not handle the + * advanced configuration features supported by the {@link LoggerDOMConfigurator} + * such as support for {@link LoggerFilter}, + custom {@link LoggerErrorHandlers}, nested appenders such as the + {@link Logger AsyncAppender}, + * etc. + * + *
All option values admit variable substitution. The + * syntax of variable substitution is similar to that of Unix + * shells. The string between an opening "${" and + * closing "}" is interpreted as a key. The value of + * the substituted variable can be defined as a system property or in + * the configuration file itself. The value of the key is first + * searched in the defined constants, in the enviroments variables + * and if not found there, it is + * then searched in the configuration file being parsed. The + * corresponding value replaces the ${variableName} sequence.
+ *For example, if $_ENV['home'] env var is set to + * /home/xyz, then every occurrence of the sequence + * ${home} will be interpreted as + * /home/xyz. See {@link LoggerOptionConverter::getSystemProperty()} + * for details.
+ * + * @author VxRThe function {@link PHP_MANUAL#parse_ini_file} is used to read the + * file.
+ * + * The existing configuration is not cleared nor reset. + * If you require a different behavior, then call + * {@link LoggerManager::resetConfiguration()} + * method before calling {@link doConfigure()}. + * + *The configuration file consists of statements in the format + * key=value. The syntax of different configuration + * elements are discussed below. + * + *
Repository-wide threshold
+ * + *The repository-wide threshold filters logging requests by level + * regardless of logger. The syntax is: + * + *
+ * log4php.threshold=[level] + *+ * + *
The level value can consist of the string values OFF, FATAL, + * ERROR, WARN, INFO, DEBUG, ALL or a custom level value. A + * custom level value can be specified in the form + * level#classname. By default the repository-wide threshold is set + * to the lowest possible value, namely the level ALL. + *
+ * + * + *Appender configuration
+ * + *Appender configuration syntax is:
+ *+ * ; For appender named appenderName, set its class. + * ; Note: The appender name can contain dots. + * log4php.appender.appenderName=name_of_appender_class + * + * ; Set appender specific options. + * + * log4php.appender.appenderName.option1=value1 + * log4php.appender.appenderName.optionN=valueN + *+ * + * For each named appender you can configure its {@link LoggerLayout}. The + * syntax for configuring an appender's layout is: + *
+ * log4php.appender.appenderName.layout=name_of_layout_class + * log4php.appender.appenderName.layout.option1=value1 + * .... + * log4php.appender.appenderName.layout.optionN=valueN + *+ * + *
Configuring loggers
+ * + *The syntax for configuring the root logger is: + *
+ * log4php.rootLogger=[level], appenderName, appenderName, ... + *+ * + *
This syntax means that an optional level can be + * supplied followed by appender names separated by commas. + * + *
The level value can consist of the string values OFF, FATAL, + * ERROR, WARN, INFO, DEBUG, ALL or a custom level value. A + * custom level value can be specified in the form
+ * + *level#classname+ * + *
If a level value is specified, then the root level is set + * to the corresponding level. If no level value is specified, + * then the root level remains untouched. + * + *
The root logger can be assigned multiple appenders. + * + *
Each appenderName (separated by commas) will be added to + * the root logger. The named appender is defined using the + * appender syntax defined above. + * + *
For non-root categories the syntax is almost the same: + *
+ * log4php.logger.logger_name=[level|INHERITED|NULL], appenderName, appenderName, ... + *+ * + *
The meaning of the optional level value is discussed above + * in relation to the root logger. In addition however, the value + * INHERITED can be specified meaning that the named logger should + * inherit its level from the logger hierarchy.
+ * + *If no level value is supplied, then the level of the + * named logger remains untouched.
+ * + *By default categories inherit their level from the + * hierarchy. However, if you set the level of a logger and later + * decide that that logger should inherit its level, then you should + * specify INHERITED as the value for the level value. NULL is a + * synonym for INHERITED.
+ * + *Similar to the root logger syntax, each appenderName + * (separated by commas) will be attached to the named logger.
+ * + *See the appender additivity rule in the user manual for + * the meaning of the additivity flag. + * + *
ObjectRenderers
+ * + *You can customize the way message objects of a given type are + * converted to String before being logged. This is done by + * specifying a {@link LoggerObjectRenderer} + * for the object type would like to customize.
+ * + *The syntax is: + * + *
+ * log4php.renderer.name_of_rendered_class=name_of_rendering.class + *+ * + * As in, + *
+ * log4php.renderer.myFruit=myFruitRenderer + *+ * + *
Logger Factories
+ * + * The usage of custom logger factories is discouraged and no longer + * documented. + * + *Example
+ * + *An example configuration is given below. Other configuration + * file examples are given in the tests folder. + * + *
+ * ; Set options for appender named "A1". + * ; Appender "A1" will be a SyslogAppender + * log4php.appender.A1=SyslogAppender + * + * ; The syslog daemon resides on www.abc.net + * log4php.appender.A1.SyslogHost=www.abc.net + * + * ; A1's layout is a LoggerPatternLayout, using the conversion pattern + * ; %r %-5p %c{2} %M.%L %x - %m%n. Thus, the log output will + * ; include the relative time since the start of the application in + * ; milliseconds, followed by the level of the log request, + * ; followed by the two rightmost components of the logger name, + * ; followed by the callers method name, followed by the line number, + * ; the nested disgnostic context and finally the message itself. + * ; Refer to the documentation of LoggerPatternLayout} for further information + * ; on the syntax of the ConversionPattern key. + * log4php.appender.A1.layout=LoggerPatternLayout + * log4php.appender.A1.layout.ConversionPattern="%-4r %-5p %c{2} %M.%L %x - %m%n" + * + * ; Set options for appender named "A2" + * ; A2 should be a LoggerAppenderRollingFile, with maximum file size of 10 MB + * ; using at most one backup file. A2's layout is TTCC, using the + * ; ISO8061 date format with context printing enabled. + * log4php.appender.A2=LoggerAppenderRollingFile + * log4php.appender.A2.MaxFileSize=10MB + * log4php.appender.A2.MaxBackupIndex=1 + * log4php.appender.A2.layout=LoggerLayoutTTCC + * log4php.appender.A2.layout.ContextPrinting="true" + * log4php.appender.A2.layout.DateFormat="%c" + * + * ; Root logger set to DEBUG using the A2 appender defined above. + * log4php.rootLogger=DEBUG, A2 + * + * ; Logger definitions: + * ; The SECURITY logger inherits is level from root. However, it's output + * ; will go to A1 appender defined above. It's additivity is non-cumulative. + * log4php.logger.SECURITY=INHERIT, A1 + * log4php.additivity.SECURITY=false + * + * ; Only warnings or above will be logged for the logger "SECURITY.access". + * ; Output will go to A1. + * log4php.logger.SECURITY.access=WARN + * + * + * ; The logger "class.of.the.day" inherits its level from the + * ; logger hierarchy. Output will go to the appender's of the root + * ; logger, A2 in this case. + * log4php.logger.class.of.the.day=INHERIT + *+ * + *
Refer to the setOption method in each Appender and + * Layout for class specific options.
+ * + *Use the ";" character at the + * beginning of a line for comments.
+ * + * @param string $url The name of the configuration file where the + * configuration information is stored. + * @param LoggerHierarchy &$repository the repository to apply the configuration + */ + function doConfigure($url, &$repository) + { + $properties = @parse_ini_file($url); + if ($properties === false) { + LoggerLog::warn("LoggerPropertyConfigurator::doConfigure() cannot load '$url' configuration."); + return false; + } + return $this->doConfigureProperties($properties, $repository); + } + + + /** + * Read configuration options from properties. + * + * @see doConfigure(). + * @param array $properties + * @param LoggerHierarchy &$hierarchy + */ + function doConfigureProperties($properties, &$hierarchy) + { + $value = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_DEBUG_KEY]; + + if (!empty($value)) { + LoggerLog::internalDebugging(LoggerOptionConverter::toBoolean($value, LoggerLog::internalDebugging())); + } + + $thresholdStr = @$properties[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_THRESHOLD_PREFIX]; + $hierarchy->setThreshold(LoggerOptionConverter::toLevel($thresholdStr, LoggerLevel::getLevelAll())); + + $this->configureRootCategory($properties, $hierarchy); + $this->configureLoggerFactory($properties); + $this->parseCatsAndRenderers($properties, $hierarchy); + + LoggerLog::debug("LoggerPropertyConfigurator::doConfigureProperties() Finished configuring."); + + return true; + } + + // -------------------------------------------------------------------------- + // Internal stuff + // -------------------------------------------------------------------------- + + /** + * Check the provided Properties object for a + * {@link LoggerFactory} entry specified by + * {@link LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY}. + * + * If such an entry exists, an attempt is made to create an instance using + * the default constructor. + * This instance is used for subsequent Category creations + * within this configurator. + * + * @see parseCatsAndRenderers() + * @param array $props array of properties + */ + function configureLoggerFactory($props) + { + $factoryFqcn = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_FACTORY_KEY]; + if(!empty($factoryFqcn)) { + $factoryClassName = basename($factoryFqcn); + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() Trying to load factory [" . + $factoryClassName . + "]." + ); + + if (!class_exists($factoryClassName)) + @include_once("{$factoryFqcn}.php"); + if (class_exists($factoryClassName)) { + $loggerFactory = new $factoryClassName(); + } else { + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() Unable to load factory [" . + $factoryClassName . + "]. Using default." + ); + $loggerFactory = $this->loggerFactory; + } + + LoggerLog::debug( + "LoggerPropertyConfigurator::configureLoggerFactory() ". + "Setting properties for category factory [" . get_class($loggerFactory) . "]." + ); + + LoggerPropertySetter::setPropertiesByObject($loggerFactory, $props, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_FACTORY_PREFIX . "."); + } + } + + /** + * @param array $props array of properties + * @param LoggerHierarchy &$hierarchy + */ + function configureRootCategory($props, &$hierarchy) + { + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX; + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_LOGGER_PREFIX]; + + if(empty($value)) { + $value = @$props[LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX]; + $effectivePrefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ROOT_CATEGORY_PREFIX; + } + + if (empty($value)) { + LoggerLog::debug( + "LoggerPropertyConfigurator::configureRootCategory() ". + "Could not find root logger information. Is this OK?" + ); + } else { + $root =& $hierarchy->getRootLogger(); + // synchronized(root) { + $this->parseCategory( + $props, + $root, + $effectivePrefix, + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME, + $value + ); + // } + } + } + + /** + * Parse non-root elements, such non-root categories and renderers. + * + * @param array $props array of properties + * @param LoggerHierarchy &$hierarchy + */ + function parseCatsAndRenderers($props, &$hierarchy) + { + while(list($key,$value) = each($props)) { + if( strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0 or + strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { + if(strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX) === 0) { + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_CATEGORY_PREFIX)); + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX) === 0) { + $loggerName = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_LOGGER_PREFIX)); + } + $logger =& $hierarchy->getLogger($loggerName, $this->loggerFactory); + // synchronized(logger) { + $this->parseCategory($props, $logger, $key, $loggerName, $value); + $this->parseAdditivityForLogger($props, $logger, $loggerName); + // } + } elseif (strpos($key, LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX) === 0) { + $renderedClass = substr($key, strlen(LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_RENDERER_PREFIX)); + $renderingClass = $value; + if (method_exists($hierarchy, 'addrenderer')) { + LoggerRendererMap::addRenderer($hierarchy, $renderedClass, $renderingClass); + } + } + } + } + + /** + * Parse the additivity option for a non-root category. + * + * @param array $props array of properties + * @param Logger &$cat + * @param string $loggerName + */ + function parseAdditivityForLogger($props, &$cat, $loggerName) + { + $value = LoggerOptionConverter::findAndSubst( + LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName, + $props + ); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAdditivityForLogger() ". + "Handling " . LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_ADDITIVITY_PREFIX . $loggerName . "=[{$value}]" + ); + // touch additivity only if necessary + if(!empty($value)) { + $additivity = LoggerOptionConverter::toBoolean($value, true); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAdditivityForLogger() ". + "Setting additivity for [{$loggerName}] to [{$additivity}]" + ); + $cat->setAdditivity($additivity); + } + } + + /** + * This method must work for the root category as well. + * + * @param array $props array of properties + * @param Logger &$logger + * @param string $optionKey + * @param string $loggerName + * @param string $value + * @return Logger + */ + function &parseCategory($props, &$logger, $optionKey, $loggerName, $value) + { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Parsing for [{$loggerName}] with value=[{$value}]." + ); + + // We must skip over ',' but not white space + $st = explode(',', $value); + + // If value is not in the form ", appender.." or "", then we should set + // the level of the loggeregory. + + if(!(@$value{0} == ',' || empty($value))) { + // just to be on the safe side... + if(sizeof($st) == 0) + return; + + $levelStr = current($st); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Level token is [$levelStr]." + ); + + // If the level value is inherited, set category level value to + // null. We also check that the user has not specified inherited for the + // root category. + if('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) { + if ($loggerName == LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_INTERNAL_ROOT_NAME) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseCategory() ". + "The root logger cannot be set to null." + ); + } else { + $logger->setLevel(null); + } + } else { + $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug())); + } + } + + // Begin by removing all existing appenders. + $logger->removeAllAppenders(); + while($appenderName = next($st)) { + $appenderName = trim($appenderName); + if(empty($appenderName)) + continue; + LoggerLog::debug( + "LoggerPropertyConfigurator::parseCategory() ". + "Parsing appender named [{$appenderName}]." + ); + $appender =& $this->parseAppender($props, $appenderName); + if($appender !== null) { + $logger->addAppender($appender); + } + } + } + + /** + * @param array $props array of properties + * @param string $appenderName + * @return LoggerAppender + */ + function &parseAppender($props, $appenderName) + { + $appender =& LoggerAppender::singleton($appenderName); + if($appender !== null) { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Appender [{$appenderName}] was already parsed." + ); + return $appender; + } + // Appender was not previously initialized. + $prefix = LOG4PHP_LOGGER_PROPERTY_CONFIGURATOR_APPENDER_PREFIX . $appenderName; + $layoutPrefix = $prefix . ".layout"; + $appenderClass = @$props[$prefix]; + if (!empty($appenderClass)) { + $appender =& LoggerAppender::singleton($appenderName, $appenderClass); + if($appender === null) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "Could not instantiate appender named [$appenderName]." + ); + return null; + } + } else { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "Could not instantiate appender named [$appenderName] with null className." + ); + return null; + } + + $appender->setName($appenderName); + if( $appender->requiresLayout() ) { + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsing layout section for [$appenderName]." + ); + $layoutClass = @$props[$layoutPrefix]; + $layoutClass = LoggerOptionConverter::substVars($layoutClass, $props); + if (empty($layoutClass)) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "layout class is empty in '$layoutPrefix'. Using Simple layout" + ); + $layout = LoggerLayout::factory('LoggerLayoutSimple'); + } else { + $layout = LoggerLayout::factory($layoutClass); + + if($layout === null) { + LoggerLog::warn( + "LoggerPropertyConfigurator::parseAppender() ". + "cannot create layout '$layoutClass'. Using Simple layout" + ); + $layout = LoggerLayout::factory('LoggerLayoutSimple'); + } + } + + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsing layout options for [$appenderName]." + ); + LoggerPropertySetter::setPropertiesByObject($layout, $props, $layoutPrefix . "."); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "End Parsing layout options for [$appenderName]." + ); + $appender->setLayout($layout); + + } + LoggerPropertySetter::setPropertiesByObject($appender, $props, $prefix . "."); + LoggerLog::debug( + "LoggerPropertyConfigurator::parseAppender() ". + "Parsed [{$appenderName}] options." + ); + return $appender; + } + +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/LoggerManager.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/LoggerManager.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/LoggerManager.php (revision 18220) @@ -0,0 +1,257 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details). + *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * LOG4PHP_DIR points to the log4php root directory. + * + * If not defined it will be set automatically when the first package classfile + * is included + * + * @var string + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/LoggerHierarchy.php'); + +if (!defined('LOG4PHP_DEFAULT_INIT_OVERRIDE')) { + if (isset($_ENV['log4php.defaultInitOverride'])) { + /** + * @ignore + */ + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', + LoggerOptionConverter::toBoolean($_ENV['log4php.defaultInitOverride'], false) + ); + } elseif (isset($GLOBALS['log4php.defaultInitOverride'])) { + /** + * @ignore + */ + define('LOG4PHP_DEFAULT_INIT_OVERRIDE', + LoggerOptionConverter::toBoolean($GLOBALS['log4php.defaultInitOverride'], false) + ); + } else { + /** + * Controls init execution + * + * With this constant users can skip the default init procedure that is + * called when this file is included. + * + *If it is not user defined, log4php tries to autoconfigure using (in order):
+ * + * - the$_ENV['log4php.defaultInitOverride']
variable.
+ * - the $GLOBALS['log4php.defaultInitOverride']
global variable.
+ * - defaults to false
+ *
+ * @var boolean
+ */
+ define('LOG4PHP_DEFAULT_INIT_OVERRIDE', false);
+ }
+}
+
+if (!defined('LOG4PHP_CONFIGURATION')) {
+ if (isset($_ENV['log4php.configuration'])) {
+ /**
+ * @ignore
+ */
+ define('LOG4PHP_CONFIGURATION', trim($_ENV['log4php.configuration']));
+ } else {
+ /**
+ * Configuration file.
+ *
+ * This constant tells configurator classes where the configuration + * file is located.
+ *If not set by user, log4php tries to set it automatically using + * (in order):
+ * + * - the$_ENV['log4php.configuration']
enviroment variable.
+ * - defaults to 'log4php.properties'.
+ *
+ * @var string
+ */
+ define('LOG4PHP_CONFIGURATION', 'log4php.properties');
+ }
+}
+
+if (!defined('LOG4PHP_CONFIGURATOR_CLASS')) {
+ if ( strtolower(substr( LOG4PHP_CONFIGURATION, -4 )) == '.xml') {
+ /**
+ * @ignore
+ */
+ define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/xml/LoggerDOMConfigurator');
+ } else {
+ /**
+ * Holds the configurator class name.
+ *
+ * This constant is set with the fullname (path included but non the + * .php extension) of the configurator class that init procedure will use.
+ *If not set by user, log4php tries to set it automatically.
+ *If {@link LOG4PHP_CONFIGURATION} has '.xml' extension set the + * constants to '{@link LOG4PHP_DIR}/xml/{@link LoggerDOMConfigurator}'.
+ *Otherwise set the constants to + * '{@link LOG4PHP_DIR}/{@link LoggerPropertyConfigurator}'.
+ * + *Security Note: classfile pointed by this constant will be brutally
+ * included with a:
+ * @include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");
This procedure tries to configure the {@link LoggerHierarchy} using the + * configurator class defined via {@link LOG4PHP_CONFIGURATOR_CLASS} that tries + * to load the configurator file defined in {@link LOG4PHP_CONFIGURATION}. + * If something goes wrong a warn is raised.
+ *Users can skip this procedure using {@link LOG4PHP_DEFAULT_INIT_OVERRIDE} + * constant.
+ * + * @return boolean + */ +function LoggerManagerDefaultInit() +{ + $configuratorClass = basename(LOG4PHP_CONFIGURATOR_CLASS); + if (!class_exists($configuratorClass)) { + @include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php"); + } + if (class_exists($configuratorClass)) { + + return call_user_func(array($configuratorClass, 'configure'), LOG4PHP_CONFIGURATION); + + } else { + LoggerLog::warn("LoggerManagerDefaultInit() Configurator '{$configuratorClass}' doesnt exists"); + return false; + } +} + +/** + * Use the LoggerManager to get Logger instances. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/spi/LoggerFactory.php'); + +/** + * Creates instances of {@link Logger} with a given name. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage layouts + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX', 'log4j'); +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS', 'http://jakarta.apache.org/log4j/'); + +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX', 'log4php'); +define('LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS', 'http://www.vxr.it/log4php/'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerTransform.php'); + +/** + * The output of the LoggerXmlLayout consists of a series of log4php:event elements. + * + *Parameters: {@link $locationInfo}.
+ * + *It does not output a complete well-formed XML file. + * The output is designed to be included as an external entity in a separate file to form + * a correct XML file.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage layouts + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +if (!defined('LOG4PHP_LINE_SEP')) { + if (substr(php_uname(), 0, 7) == "Windows") { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\r\n"); + } else { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\n"); + } +} + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * This layout outputs events in a HTML table. + * + * Parameters are: {@link $title}, {@link $locationInfo}. + * + * @author VxRIf you are embedding this layout within a {@link LoggerAppenderMail} + * or a {@link LoggerAppenderMailEvent} then make sure to set the + * LocationInfo option of that appender as well. + * @var boolean + */ + var $locationInfo = false; + + /** + * The Title option takes a String value. This option sets the + * document title of the generated HTML document. + * Defaults to 'Log4php Log Messages'. + * @var string + */ + var $title = "Log4php Log Messages"; + + /** + * Constructor + */ + function LoggerLayoutHtml() + { + return; + } + + /** + * The LocationInfo option takes a boolean value. By + * default, it is set to false which means there will be no location + * information output by this layout. If the the option is set to + * true, then the file name and line number of the statement + * at the origin of the log statement will be output. + * + *
If you are embedding this layout within a {@link LoggerAppenderMail} + * or a {@link LoggerAppenderMailEvent} then make sure to set the + * LocationInfo option of that appender as well. + */ + function setLocationInfo($flag) + { + if (is_bool($flag)) { + $this->locationInfo = $flag; + } else { + $this->locationInfo = (bool)(strtolower($flag) == 'true'); + } + } + + /** + * Returns the current value of the LocationInfo option. + */ + function getLocationInfo() + { + return $this->locationInfo; + } + + /** + * The Title option takes a String value. This option sets the + * document title of the generated HTML document. + * Defaults to 'Log4php Log Messages'. + */ + function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string Returns the current value of the Title option. + */ + function getTitle() + { + return $this->title; + } + + /** + * @return string Returns the content type output by this layout, i.e "text/html". + */ + function getContentType() + { + return "text/html"; + } + + /** + * No options to activate. + */ + function activateOptions() + { + return true; + } + + /** + * @param LoggerLoggingEvent $event + * @return string + */ + function format($event) + { + $sbuf = LOG4PHP_LINE_SEP . "
Time | " . LOG4PHP_LINE_SEP; + $sbuf .= "Thread | " . LOG4PHP_LINE_SEP; + $sbuf .= "Level | " . LOG4PHP_LINE_SEP; + $sbuf .= "Category | " . LOG4PHP_LINE_SEP; + if ($this->locationInfo) + $sbuf .= "File:Line | " . LOG4PHP_LINE_SEP; + $sbuf .= "Message | " . LOG4PHP_LINE_SEP; + $sbuf .= "
---|
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage layouts + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +if (!defined('LOG4PHP_LINE_SEP')) { + if (substr(php_uname(), 0, 7) == "Windows") { + define('LOG4PHP_LINE_SEP', "\r\n"); + } else { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\n"); + } +} + + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); + +/** + * A simple layout. + * + * Returns the log statement in a format consisting of the + * level, followed by " - " and then the message. + * For example, + * INFO - "A message" + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage layouts + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +if (!defined('LOG4PHP_LINE_SEP')) { + if (substr(php_uname(), 0, 7) == "Windows") { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\r\n"); + } else { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\n"); + } +} + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); + +/** + * String constant designating no time information. Current value of + * this constant is NULL. + */ +define ('LOG4PHP_LOGGER_LAYOUT_NULL_DATE_FORMAT', 'NULL'); + +/** + * String constant designating relative time. Current value of + * this constant is RELATIVE. + */ +define ('LOG4PHP_LOGGER_LAYOUT_RELATIVE_TIME_DATE_FORMAT', 'RELATIVE'); + +/** + * TTCC layout format consists of time, thread, category and nested + * diagnostic context information, hence the name. + * + *Each of the four fields can be individually enabled or + * disabled. The time format depends on the DateFormat used.
+ * + *If no dateFormat is specified it defaults to '%c'. + * See php {@link PHP_MANUAL#date} function for details.
+ * + * Params: + * - {@link $threadPrinting} (true|false) enable/disable pid reporting. + * - {@link $categoryPrefixing} (true|false) enable/disable logger category reporting. + * - {@link $contextPrinting} (true|false) enable/disable NDC reporting. + * - {@link $microSecondsPrinting} (true|false) enable/disable micro seconds reporting in timestamp. + * - {@link $dateFormat} (string) set date format. See php {@link PHP_MANUAL#date} function for details. + * + * @author VxRTime, thread, category are printed depending on options. + * + * @param LoggerLoggingEvent $event + * @return string + */ + function format($event) + { + $timeStamp = (float)$event->getTimeStamp(); + $format = strftime($this->dateFormat, (int)$timeStamp); + + if ($this->microSecondsPrinting) { + $usecs = round(($timeStamp - (int)$timeStamp) * 1000); + $format .= sprintf(',%03d', $usecs); + } + + $format .= ' '; + + if ($this->threadPrinting) + $format .= '['.getmypid().'] '; + + $level = $event->getLevel(); + $format .= $level->toString().' '; + + if($this->categoryPrefixing) { + $format .= $event->getLoggerName().' '; + } + + if($this->contextPrinting) { + $ndc = $event->getNDC(); + if($ndc != null) { + $format .= $ndc.' '; + } + } + + $format .= '- '.$event->getRenderedMessage(); + $format .= LOG4PHP_LINE_SEP; + + return $format; + } + + function ignoresThrowable() + { + return true; + } +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/layouts/LoggerPatternLayout.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/layouts/LoggerPatternLayout.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/layouts/LoggerPatternLayout.php (revision 18220) @@ -0,0 +1,264 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage layouts + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternParser.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Default conversion Pattern + */ +define('LOG4PHP_LOGGER_PATTERN_LAYOUT_DEFAULT_CONVERSION_PATTERN', '%m%n'); + +define('LOG4PHP_LOGGER_PATTERN_LAYOUT_TTCC_CONVERSION_PATTERN', '%r [%t] %p %c %x - %m%n'); + +// Contributors: Nelson MinarThe goal of this class is to {@link format()} a {@link LoggerLoggingEvent} and return the results as a string. + * The results depend on the conversion pattern. + * The conversion pattern is closely related to the conversion pattern of the printf function in C. + * A conversion pattern is composed of literal text and format control expressions called conversion specifiers. + * You are free to insert any literal text within the conversion pattern.
+ * + *Each conversion specifier starts with a percent sign (%) and is followed by optional + * format modifiers and a conversion character.
+ * + *The conversion character specifies the type of data, e.g. category, priority, date, thread name. + * The format modifiers control such things as field width, padding, left and right justification.
+ * + * The following is a simple example. + * + *Let the conversion pattern be "%-5p [%t]: %m%n" and assume that the log4php environment + * was set to use a LoggerPatternLayout.
+ * + * Then the statements + *
+ * $root =& LoggerManager::getRoot();
+ * $root->debug("Message 1");
+ * $root->warn("Message 2");
+ *
+ * would yield the output
+ * + * DEBUG [main]: Message 1 + * WARN [main]: Message 2 + *+ * + *
Note that there is no explicit separator between text and conversion specifiers.
+ * + *The pattern parser knows when it has reached the end of a conversion specifier when it reads a conversion character. + * In the example above the conversion specifier %-5p means the priority of the logging event should be + * left justified to a width of five characters.
+ * + * Not all log4j conversion characters are implemented. The recognized conversion characters are: + * - c Used to output the category of the logging event. The category conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. + * If a precision specifier is given, then only the corresponding number of right most components of the category name will be printed. + * By default the category name is printed in full. + * For example, for the category name "a.b.c" the pattern %c{2} will output "b.c". + * - C Used to output the fully qualified class name of the caller issuing the logging request. + * This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. + * If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. + * By default the class name is output in fully qualified form. + * For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass". + * - d Used to output the date of the logging event. + * The date conversion specifier may be followed by a date format specifier enclosed between braces. + * The format specifier follows the {@link PHP_MANUAL#date} function. + * Note that the special character u is used to as microseconds replacement (to avoid replacement, + * use \u). + * For example, %d{H:i:s,u} or %d{d M Y H:i:s,u}. If no date format specifier is given then ISO8601 format is assumed. + * The date format specifier admits the same syntax as the time pattern string of the SimpleDateFormat. + * It is recommended to use the predefined log4php date formatters. + * These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying + * AbsoluteTimeDateFormat, DateTimeDateFormat and respectively ISO8601DateFormat. + * For example, %d{ISO8601} or %d{ABSOLUTE}. + * - F Used to output the file name where the logging request was issued. + * - l Used to output location information of the caller which generated the logging event. + * - L Used to output the line number from where the logging request was issued. + * - m Used to output the application supplied message associated with the logging event. + * - M Used to output the method name where the logging request was issued. + * - p Used to output the priority of the logging event. + * - r Used to output the number of milliseconds elapsed since the start of + * the application until the creation of the logging event. + * - t Used to output the name of the thread that generated the logging event. + * - x Used to output the NDC (nested diagnostic context) associated with + * the thread that generated the logging event. + * - X Used to output the MDC (mapped diagnostic context) associated with + * the thread that generated the logging event. + * The X conversion character must be followed by the key for the map placed between braces, + * as in %X{clientNumber} where clientNumber is the key. + * The value in the MDC corresponding to the key will be output. + * See {@link LoggerMDC} class for more details. + * - % The sequence %% outputs a single percent sign. + * + *By default the relevant information is output as is. + * However, with the aid of format modifiers it is possible to change the minimum field width, + * the maximum field width and justification.
+ * + *The optional format modifier is placed between the percent sign and the conversion character.
+ *The first optional format modifier is the left justification flag which is just the minus (-) character. + * Then comes the optional minimum field width modifier. + * This is a decimal constant that represents the minimum number of characters to output. + * If the data item requires fewer characters, it is padded on either the left or the right until the minimum width is reached. The default is to pad on the left (right justify) but you can specify right padding with the left justification flag. The padding character is space. If the data item is larger than the minimum field width, the field is expanded to accommodate the data. + * The value is never truncated.
+ * + *This behavior can be changed using the maximum field width modifier which is designated by a period + * followed by a decimal constant. + * If the data item is longer than the maximum field, + * then the extra characters are removed from the beginning of the data item and not from the end. + * For example, it the maximum field width is eight and the data item is ten characters long, + * then the first two characters of the data item are dropped. + * This behavior deviates from the printf function in C where truncation is done from the end.
+ * + *Below are various format modifier examples for the category conversion specifier.
+ *+ * Format modifier left justify minimum width maximum width comment + * %20c false 20 none Left pad with spaces if the category name + * is less than 20 characters long. + * %-20c true 20 none Right pad with spaces if the category name + * is less than 20 characters long. + * %.30c NA none 30 Truncate from the beginning if the category name + * is longer than 30 characters. + * %20.30c false 20 30 Left pad with spaces if the category name + * is shorter than 20 characters. + * However, if category name is longer than 30 chars, + * then truncate from the beginning. + * %-20.30c true 20 30 Right pad with spaces if the category name is + * shorter than 20 chars. + * However, if category name is longer than 30 chars, + * then truncate from the beginning. + *+ * + * @author VxR
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage xml + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/LoggerAppender.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php'); +require_once(LOG4PHP_DIR . '/LoggerManager.php'); + +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE', 1000); +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE', 1010); +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE', 1020); +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE', 1030); +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE', 1040); + +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_DEFAULT_FILENAME', './log4php.xml'); + +/** + * @var string the default configuration document + */ +define('LOG4PHP_LOGGER_DOM_CONFIGURATOR_DEFAULT_CONFIGURATION', +' +Read the log4php.dtd included in the documentation directory. Note that + * php parser does not validate the document.
+ * + *Sometimes it is useful to see how log4php is reading configuration + * files. You can enable log4php internal logging by setting the debug + * attribute in the log4php:configuration element. As in + *
+ * <log4php:configuration debug="true" xmlns:log4php="http://www.vxr.it/log4php/"> + * ... + * </log4php:configuration> + *+ * + *
There are sample XML files included in the package under tests/ + * subdirectories.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage helpers + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +if (!defined('LOG4PHP_LINE_SEP')) { + if (substr(php_uname(), 0, 7) == "Windows") { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\r\n"); + } else { + /** + * @ignore + */ + define('LOG4PHP_LINE_SEP', "\n"); + } +} + +/** + */ +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternConverter.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerFormattingInfo.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +define('LOG4PHP_LOGGER_PATTERN_PARSER_ESCAPE_CHAR', '%'); + +define('LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE', 0); +define('LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE', 1); +define('LOG4PHP_LOGGER_PATTERN_PARSER_MINUS_STATE', 2); +define('LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE', 3); +define('LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE', 4); +define('LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE', 5); + +define('LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER', 1000); +define('LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER', 1001); +define('LOG4PHP_LOGGER_PATTERN_PARSER_CLASS_LOCATION_CONVERTER', 1002); +define('LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER', 1003); +define('LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER', 1004); + +define('LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER', 2000); +define('LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER', 2001); +define('LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER', 2002); +define('LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER', 2003); +define('LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER', 2004); + +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601', 'Y-m-d H:i:s,u'); +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ABSOLUTE', 'H:i:s'); +define('LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_DATE', 'd M Y H:i:s,u'); + +/** + * Most of the work of the {@link LoggerPatternLayout} class + * is delegated to the {@link LoggerPatternParser} class. + * + *It is this class that parses conversion patterns and creates + * a chained list of {@link LoggerPatternConverter} converters.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage helpers + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_START', ''); +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END', ']]>'); +define('LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END', + LOG4PHP_LOGGER_TRANSFORM_CDATA_END . + LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END . + LOG4PHP_LOGGER_TRANSFORM_CDATA_START +); + +/** + * Utility class for transforming strings. + * + * @log4j-class org.apache.log4j.helpers.Transform + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage helpers + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); + +define('LOG4PHP_OPTION_CONVERTER_DELIM_START', '${'); +define('LOG4PHP_OPTION_CONVERTER_DELIM_STOP', '}'); +define('LOG4PHP_OPTION_CONVERTER_DELIM_START_LEN', 2); +define('LOG4PHP_OPTION_CONVERTER_DELIM_STOP_LEN', 1); + +/** + * A convenience class to convert property values to specific types. + * + * @author VxRCase of value is unimportant.
+ * + * @param string $value + * @param boolean $default + * @return boolean + * + * @static + */ + function toBoolean($value, $default) + { + if($value === null) + return $default; + if ($value == 1) + return true; + $trimmedVal = strtolower(trim($value)); + if ("true" == $trimmedVal or "yes" == $trimmedVal) + return true; + if ("false" == $trimmedVal) + return false; + return $default; + } + + /** + * @param string $value + * @param integer $default + * @return integer + * @static + */ + function toInt($value, $default) + { + $value = trim($value); + if (is_numeric($value)) { + return (int)$value; + } else { + return $default; + } + } + + /** + * Converts a standard or custom priority level to a Level + * object. + * + *If $value is of form "level#full_file_classname", + * where full_file_classname means the class filename with path + * but without php extension, then the specified class' toLevel() method + * is called to process the specified level string; if no '#' + * character is present, then the default {@link LoggerLevel} + * class is used to process the level value.
+ * + *As a special case, if the $value parameter is + * equal to the string "NULL", then the value null will + * be returned.
+ * + *If any error occurs while converting the value to a level, + * the $defaultValue parameter, which may be + * null, is returned.
+ * + *Case of $value is insignificant for the level level, but is + * significant for the class name part, if present.
+ * + * @param string $value + * @param LoggerLevel $defaultValue + * @return LoggerLevel a {@link LoggerLevel} or null + * @static + */ + function toLevel($value, $defaultValue) + { + if($value === null) + return $defaultValue; + + $hashIndex = strpos($value, '#'); + if ($hashIndex === false) { + if("NULL" == strtoupper($value)) { + return null; + } else { + // no class name specified : use standard Level class + return LoggerLevel::toLevel($value, $defaultValue); + } + } + + $result = $defaultValue; + + $clazz = substr($value, ($hashIndex + 1)); + $levelName = substr($value, 0, $hashIndex); + + // This is degenerate case but you never know. + if("NULL" == strtoupper($levelName)) { + return null; + } + + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}]:pri=[{$levelName}]"); + + if (!class_exists($clazz)) + @include_once("{$clazz}.php"); + + $clazz = basename($clazz); + + if (class_exists($clazz)) { + $result = @call_user_func(array($clazz, 'toLevel'), $value, $defaultValue); + if (!is_a($result, 'loggerlevel')) { + LoggerLog::debug("LoggerOptionConverter::toLevel():class=[{$clazz}] cannot call toLevel(). Returning default."); + $result = $defaultValue; + } + } else { + LoggerLog::warn("LoggerOptionConverter::toLevel() class '{$clazz}' doesnt exists."); + } + return $result; + } + + /** + * @param string $value + * @param float $default + * @return float + * + * @static + */ + function toFileSize($value, $default) + { + if ($value === null) + return $default; + + $s = strtoupper(trim($value)); + $multiplier = (float)1; + if(($index = strpos($s, 'KB')) !== false) { + $multiplier = 1024; + $s = substr($s, 0, $index); + } elseif(($index = strpos($s, 'MB')) !== false) { + $multiplier = 1024 * 1024; + $s = substr($s, 0, $index); + } elseif(($index = strpos($s, 'GB')) !== false) { + $multiplier = 1024 * 1024 * 1024; + $s = substr($s, 0, $index); + } + if(is_numeric($s)) { + return (float)$s * $multiplier; + } else { + LoggerLog::warn("LoggerOptionConverter::toFileSize() [{$s}] is not in proper form."); + } + return $default; + } + + /** + * Find the value corresponding to $key in + * $props. Then perform variable substitution on the + * found value. + * + * @param string $key + * @param array $props + * @return string + * + * @static + */ + function findAndSubst($key, $props) + { + $value = @$props[$key]; + if(empty($value)) { + return null; + } + return LoggerOptionConverter::substVars($value, $props); + } + + /** + * Perform variable substitution in string $val from the + * values of keys found with the {@link getSystemProperty()} method. + * + *The variable substitution delimeters are ${ and }. + * + *
For example, if the "MY_CONSTANT" contains "value", then
+ * the call
+ *
+ * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}.");
+ *
+ * will set the variable $s to "Value of key is value.".
If no value could be found for the specified key, then the + * $props parameter is searched, if the value could not + * be found there, then substitution defaults to the empty string.
+ * + *For example, if {@link getSystemProperty()} cannot find any value for the key
+ * "inexistentKey", then the call
+ *
+ * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
+ *
+ * will set $s to "Value of inexistentKey is []".
A warn is thrown if $val contains a start delimeter "${" + * which is not balanced by a stop delimeter "}" and an empty string is returned.
+ * + * @log4j-author Avy Sharell + * + * @param string $val The string on which variable substitution is performed. + * @param array $props + * @return string + * + * @static + */ + function substVars($val, $props = null) + { + LoggerLog::debug("LoggerOptionConverter::substVars():val=[{$val}]"); + + $sbuf = ''; + $i = 0; + while(true) { + $j = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_START, $i); + if ($j === false) { + LoggerLog::debug("LoggerOptionConverter::substVars() no more variables"); + // no more variables + if ($i == 0) { // this is a simple string + LoggerLog::debug("LoggerOptionConverter::substVars() simple string"); + return $val; + } else { // add the tail string which contails no variables and return the result. + $sbuf .= substr($val, $i); + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]. Returning sbuf"); + return $sbuf; + } + } else { + + $sbuf .= substr($val, $i, $j-$i); + LoggerLog::debug("LoggerOptionConverter::substVars():sbuf=[{$sbuf}]:i={$i}:j={$j}."); + $k = strpos($val, LOG4PHP_OPTION_CONVERTER_DELIM_STOP, $j); + if ($k === false) { + LoggerLog::warn( + "LoggerOptionConverter::substVars() " . + "'{$val}' has no closing brace. Opening brace at position {$j}." + ); + return ''; + } else { + $j += LOG4PHP_OPTION_CONVERTER_DELIM_START_LEN; + $key = substr($val, $j, $k - $j); + // first try in System properties + $replacement = LoggerOptionConverter::getSystemProperty($key, null); + // then try props parameter + if($replacement == null and $props !== null) { + $replacement = @$props[$key]; + } + + if(!empty($replacement)) { + // Do variable substitution on the replacement string + // such that we can solve "Hello ${x2}" as "Hello p1" + // the where the properties are + // x1=p1 + // x2=${x1} + $recursiveReplacement = LoggerOptionConverter::substVars($replacement, $props); + $sbuf .= $recursiveReplacement; + } + $i = $k + LOG4PHP_OPTION_CONVERTER_DELIM_STOP_LEN; + } + } + } + } + +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/helpers/LoggerPatternConverter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/helpers/LoggerPatternConverter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/helpers/LoggerPatternConverter.php (revision 18220) @@ -0,0 +1,505 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details). + *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage helpers + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/helpers/LoggerPatternParser.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Array for fast space padding + * Used by {@link LoggerPatternConverter::spacePad()}. + */ +$GLOBALS['log4php.LoggerPatternConverter.spaces'] = array(" ", " ", " ", " ", //1,2,4,8 spaces + " ", // 16 spaces + " " ); // 32 spaces + +/** + * LoggerPatternConverter is an abstract class that provides the formatting + * functionality that derived classes need. + * + *Conversion specifiers in a conversion patterns are parsed to + * individual PatternConverters. Each of which is responsible for + * converting a logging event in a converter specific manner.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage helpers + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * This class encapsulates the information obtained when parsing + * formatting modifiers in conversion modifiers. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage varia + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); + +/** + * This is a very simple filter based on string matching. + * + *The filter admits two options {@link $stringToMatch} and + * {@link $acceptOnMatch}. If there is a match (using {@link PHP_MANUAL#strpos} + * between the value of the {@link $stringToMatch} option and the message + * of the {@link LoggerLoggingEvent}, + * then the {@link decide()} method returns {@link LOG4PHP_LOGGER_FILTER_ACCEPT} if + * the AcceptOnMatch option value is true, if it is false then + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match, {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} + * is returned.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage varia + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); + +/** + * This is a very simple filter based on level matching. + * + *The filter admits two options LevelToMatch and + * AcceptOnMatch. If there is an exact match between the value + * of the LevelToMatch option and the level of the + * {@link LoggerLoggingEvent}, then the {@link decide()} method returns + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} in case the AcceptOnMatch + * option value is set to true, if it is false then + * {@link LOG4PHP_LOGGER_FILTER_DENY} is returned. If there is no match, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage varia + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); + +/** + * This is a very simple filter based on level matching, which can be + * used to reject messages with priorities outside a certain range. + * + *The filter admits three options LevelMin, LevelMax + * and AcceptOnMatch.
+ * + *If the level of the {@link LoggerLoggingEvent} is not between Min and Max + * (inclusive), then {@link LOG4PHP_LOGGER_FILTER_DENY} is returned.
+ * + *If the Logging event level is within the specified range, then if + * AcceptOnMatch is true, + * {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, and if + * AcceptOnMatch is false, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned.
+ * + *If LevelMin is not defined, then there is no + * minimum acceptable level (ie a level is never rejected for + * being too "low"/unimportant). If LevelMax is not + * defined, then there is no maximum acceptable level (ie a + * level is never rejected for beeing too "high"/important).
+ * + *Refer to the {@link LoggerAppenderSkeleton::setThreshold()} method + * available to all appenders extending {@link LoggerAppenderSkeleton} + * for a more convenient way to filter out events by level.
+ * + * @log4j-class org.apache.log4j.varia.LevelRangeFilter + * @log4j-author Simon Kitching + * @log4j-author based on code by Ceki Gülcü + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage varia + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); + +/** + * This filter drops all logging events. + * + *You can add this filter to the end of a filter chain to + * switch from the default "accept all unless instructed otherwise" + * filtering behaviour to a "deny all unless instructed otherwise" + * behaviour.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + * Extend this abstract class to create your own log layout format. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerHierarchy.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerLoggingEvent.php'); + +/** + * This class has been deprecated and replaced by the Logger subclass. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLog.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/Logger.php'); +require_once(LOG4PHP_DIR . '/LoggerRoot.php'); +require_once(LOG4PHP_DIR . '/or/LoggerRendererMap.php'); +require_once(LOG4PHP_DIR . '/LoggerDefaultCategoryFactory.php'); + +/** + * This class is specialized in retrieving loggers by name and also maintaining + * the logger hierarchy. + * + *The casual user does not have to deal with this class directly.
+ * + *The structure of the logger hierarchy is maintained by the + * getLogger method. The hierarchy is such that children link + * to their parent but parents do not have any pointers to their + * children. Moreover, loggers can be instantiated in any order, in + * particular descendant before ancestor.
+ * + *In case a descendant is created before a particular ancestor, + * then it creates a provision node for the ancestor and adds itself + * to the provision node. Other descendants of the same ancestor add + * themselves to the previously created provision node.
+ * + * @author VxRExisting categories are not removed. They are just reset. + * + *
This method should be used sparingly and with care as it will + * block all logging until it is completed.
+ */ + function resetConfiguration() + { + $root =& $this->getRootLogger(); + + $root->setLevel(LoggerLevel::getLevelDebug()); + $this->setThreshold(LoggerLevel::getLevelAll()); + $this->shutDown(); + $loggers =& $this->getCurrentLoggers(); + $enumLoggers = sizeof($loggers); + for ($i = 0; $i < $enumLoggers; $i++) { + $loggers[$i]->setLevel(null); + $loggers[$i]->setAdditivity(true); + $loggers[$i]->setResourceBundle(null); + } + $this->rendererMap->clear(); + } + + /** + * @deprecated Deprecated with no replacement. + */ + function setDisableOverride($override) + { + return; + } + + /** + * Used by subclasses to add a renderer to the hierarchy passed as parameter. + * @param string $renderedClass a LoggerRenderer class name + * @param LoggerRenderer $renderer + * + */ + function setRenderer($renderedClass, $renderer) + { + $this->rendererMap->put($renderedClass, $renderer); + } + + /** + * set a new threshold level + * + * @param LoggerLevel $l + */ + function setThreshold($l) + { + if ($l !== null) + $this->threshold = $l; + } + + /** + * Shutting down a hierarchy will safely close and remove + * all appenders in all categories including the root logger. + * + *Some appenders such as {@link LoggerSocketAppender} + * need to be closed before the + * application exists. Otherwise, pending logging events might be + * lost. + * + *
The shutdown method is careful to close nested + * appenders before closing regular appenders. This is allows + * configurations where a regular appender is attached to a logger + * and again to a nested appender. + */ + function shutdown() + { + $this->root->removeAllAppenders(); + $cats =& $this->getCurrentLoggers(); + $enumCats = sizeof($cats); + if ($enumCats > 0) { + for ($i = 0; $i < $enumCats; $i++) { + $cats[$i]->removeAllAppenders(); + } + } + } +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertySetter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertySetter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertySetter.php (revision 18220) @@ -0,0 +1,161 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage config + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/LoggerLog.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); + +/** + * General purpose Object property setter. Clients repeatedly invokes + * {@link setProperty()} in order to invoke setters + * on the Object specified in the constructor. + * + * Usage: + *
+ * $ps = new LoggerPropertySetter($anObject);
+ * $ps->set("name", "Joe");
+ * $ps->set("age", 32);
+ * $ps->set("isMale", true);
+ *
+ * will cause the invocations
+ *
+ * $anObject->setName("Joe");
+ * $anObject->setAge(32);
+ * $anObject->setMale(true)
+ *
+ * if such methods exist.
+ *
+ * @author VxR properties
are parsed relative to a
+ * prefix
.
+ *
+ * @param object &$obj The object to configure.
+ * @param array $properties An array containing keys and values.
+ * @param string $prefix Only keys having the specified prefix will be set.
+ * @static
+ */
+ function setPropertiesByObject(&$obj, $properties, $prefix)
+ {
+ $pSetter = new LoggerPropertySetter($obj);
+ return $pSetter->setProperties($properties, $prefix);
+ }
+
+
+ /**
+ * Set the properites for the object that match the
+ * prefix
passed as parameter.
+ *
+ * @param array $properties An array containing keys and values.
+ * @param string $prefix Only keys having the specified prefix will be set.
+ */
+ function setProperties($properties, $prefix)
+ {
+ LoggerLog::debug("LoggerOptionConverter::setProperties():prefix=[{$prefix}]");
+
+ $len = strlen($prefix);
+ while (list($key,) = each($properties)) {
+ if (strpos($key, $prefix) === 0) {
+ if (strpos($key, '.', ($len + 1)) > 0)
+ continue;
+ $value = LoggerOptionConverter::findAndSubst($key, $properties);
+ $key = substr($key, $len);
+ if ($key == 'layout' and is_a($this->obj, 'loggerappender')) {
+ continue;
+ }
+ $this->setProperty($key, $value);
+ }
+ }
+ $this->activate();
+ }
+
+ /**
+ * Set a property on this PropertySetter's Object. If successful, this
+ * method will invoke a setter method on the underlying Object. The
+ * setter is the one for the specified property name and the value is
+ * determined partly from the setter argument type and partly from the
+ * value specified in the call to this method.
+ *
+ * If the setter expects a String no conversion is necessary. + * If it expects an int, then an attempt is made to convert 'value' + * to an int using new Integer(value). If the setter expects a boolean, + * the conversion is by new Boolean(value). + * + * @param string $name name of the property + * @param string $value String value of the property + */ + function setProperty($name, $value) + { + LoggerLog::debug("LoggerOptionConverter::setProperty():name=[{$name}]:value=[{$value}]"); + + if ($value === null) return; + + $method = "set" . ucfirst($name); + + if (!method_exists($this->obj, $method)) { + LoggerLog::warn( + "LoggerOptionConverter::setProperty() No such setter method for [{$name}] property in " . + get_class($this->obj) . "." + ); + } else { + return call_user_func(array(&$this->obj, $method), $value); + } + } + + function activate() + { + LoggerLog::debug("LoggerOptionConverter::activate()"); + + if (method_exists($this->obj, 'activateoptions')) { + return call_user_func(array(&$this->obj, 'activateoptions')); + } else { + LoggerLog::debug("LoggerOptionConverter::activate() Nothing to activate."); + } + } +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertyGetter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertyGetter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/config/LoggerPropertyGetter.php (revision 18220) @@ -0,0 +1,37 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage config + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/LoggerCategory.php'); +require_once(LOG4PHP_DIR . '/LoggerManager.php'); + +/** + * Main class for logging operations + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + * Helper class for internal logging + * + *It uses php {@link PHP_MANUAL#trigger_error trigger_error()} function + * to output messages.
+ *You need to recode methods to output messages in a different way.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/Logger.php'); + +/** + * The root logger. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage or + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/or/LoggerObjectRenderer.php'); + +/** + * The default Renderer renders objects by type casting + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage or + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + * Subclass this abstract class in order to render objects as strings. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage or + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/or/LoggerDefaultRenderer.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Map class objects to an {@link LoggerObjectRenderer}. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Log events to an email address. It will be created an email for each event. + * + *Parameters are + * {@link $smtpHost} (optional), + * {@link $port} (optional), + * {@link $from} (optional), + * {@link $to}, + * {@link $subject} (optional).
+ *A layout is required.
+ * + * @author Domenico LordiDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); +require_once('DB.php'); + +/** + * Appends log events to a db table using PEAR::DB class. + * + *This appender uses a table in a database to log events.
+ *Parameters are {@link $dsn}, {@link $createTable}, {@link table} and {@link $sql}.
+ *See examples in test directory.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php'); + +/** + * LoggerAppenderRollingFile extends LoggerAppenderFile to backup the log files + * when they reach a certain size. + * + *Parameters are {@link $maxFileSize}, {@link $maxBackupIndex}.
+ * + *Contributors: Sergio Strampelli.
+ * + * @author VxRIn configuration files, the MaxFileSize option takes a + * long integer in the range 0 - 2^63. You can specify the value + * with the suffixes "KB", "MB" or "GB" so that the integer is + * interpreted being expressed respectively in kilobytes, megabytes + * or gigabytes. For example, the value "10KB" will be interpreted + * as 10240.
+ *The default maximum file size is 10MB.
+ * + *Note that MaxFileSize cannot exceed 2 GB.
+ * + * @var integer + */ + var $maxFileSize = 10485760; + + /** + * Set the maximum number of backup files to keep around. + * + *The MaxBackupIndex option determines how many backup + * files are kept before the oldest is erased. This option takes + * a positive integer value. If set to zero, then there will be no + * backup files and the log file will be truncated when it reaches + * MaxFileSize.
+ *There is one backup file by default.
+ * + * @var integer + */ + var $maxBackupIndex = 1; + + /** + * @var string the filename expanded + * @access private + */ + var $expandedFileName = null; + + /** + * Constructor. + * + * @param string $name appender name + */ + function LoggerAppenderRollingFile($name) + { + $this->LoggerAppenderFile($name); + } + + /** + * Returns the value of the MaxBackupIndex option. + * @return integer + */ + function getExpandedFileName() { + return $this->expandedFileName; + } + + /** + * Returns the value of the MaxBackupIndex option. + * @return integer + */ + function getMaxBackupIndex() { + return $this->maxBackupIndex; + } + + /** + * Get the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + * @return integer + */ + function getMaximumFileSize() { + return $this->maxFileSize; + } + + /** + * Implements the usual roll over behaviour. + * + *If MaxBackupIndex is positive, then files File.1, ..., File.MaxBackupIndex -1 are renamed to File.2, ..., File.MaxBackupIndex. + * Moreover, File is renamed File.1 and closed. A new File is created to receive further log output. + * + *
If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created. + */ + function rollOver() + { + // If maxBackups <= 0, then there is no file renaming to be done. + if($this->maxBackupIndex > 0) { + $fileName = $this->getExpandedFileName(); + // Delete the oldest file, to keep Windows happy. + $file = $fileName . '.' . $this->maxBackupIndex; + if (is_writable($file)) + unlink($file); + // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} + for ($i = $this->maxBackupIndex - 1; $i >= 1; $i--) { + $file = $fileName . "." . $i; + if (is_readable($file)) { + $target = $fileName . '.' . ($i + 1); + rename($file, $target); + } + } + + // Rename fileName to fileName.1 + $target = $fileName . ".1"; + + $this->closeFile(); // keep windows happy. + + $file = $fileName; + rename($file, $target); + } + + $this->setFile($fileName, false); + unset($this->fp); + $this->activateOptions(); + } + + function setFileName($fileName) + { + $this->fileName = $fileName; + $this->expandedFileName = realpath($fileName); + LoggerLog::debug("LoggerAppenderRollingFile::setFileName():filename=[{$fileName}]:expandedFileName=[{$this->expandedFileName}]"); + } + + + /** + * Set the maximum number of backup files to keep around. + * + *
The MaxBackupIndex option determines how many backup + * files are kept before the oldest is erased. This option takes + * a positive integer value. If set to zero, then there will be no + * backup files and the log file will be truncated when it reaches + * MaxFileSize. + * + * @param mixed $maxBackups + */ + function setMaxBackupIndex($maxBackups) + { + if (is_numeric($maxBackups)) + $this->maxBackupIndex = abs((int)$maxBackups); + } + + /** + * Set the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + * + * @param mixed $maxFileSize + * @see setMaxFileSize() + */ + function setMaximumFileSize($maxFileSize) + { + $this->setMaxFileSize($maxFileSize); + } + + /** + * Set the maximum size that the output file is allowed to reach + * before being rolled over to backup files. + *
In configuration files, the MaxFileSize option takes an + * long integer in the range 0 - 2^63. You can specify the value + * with the suffixes "KB", "MB" or "GB" so that the integer is + * interpreted being expressed respectively in kilobytes, megabytes + * or gigabytes. For example, the value "10KB" will be interpreted + * as 10240. + * + * @param mixed $value + */ + function setMaxFileSize($value) + { + $maxFileSize = null; + $numpart = substr($value,0, strlen($value) -2); + $suffix = strtoupper(substr($value, -2)); + + switch ($suffix) { + case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break; + case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break; + case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break; + default: + if (is_numeric($value)) { + $maxFileSize = (int)$value; + } + } + + if ($maxFileSize === null) { + LoggerLog::debug("LoggerAppenderRollingFile::setMaxFileSize():value=[$value] wrong declaration"); + } else { + $this->maxFileSize = abs($maxFileSize); + } + } + + /** + * @param LoggerLoggingEvent $event + */ + function append($event) + { + if ($this->fp) { + parent::append($event); + if (ftell($this->fp) > $this->getMaximumFileSize()) + $this->rollOver(); + } + } +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/appenders/LoggerAppenderPhp.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/appenders/LoggerAppenderPhp.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/appenders/LoggerAppenderPhp.php (revision 18220) @@ -0,0 +1,85 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Log events using php {@link PHP_MANUAL#trigger_error} function and a {@link LoggerLayoutTTCC} default layout. + * + *Levels are mapped as follows:
+ * - level < WARN mapped to E_USER_NOTICE + * - WARN <= level < ERROR mapped to E_USER_WARNING + * - level >= ERROR mapped to E_USER_ERROR + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +define('LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_PORT', 4446); +define('LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_TIMEOUT', 30); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Serialize events and send them to a network socket. + * + * Parameters are {@link $remoteHost}, {@link $port}, {@link $timeout}, + * {@link $locationInfo}, {@link $useXml} and {@link $log4jNamespace}. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * A NullAppender merely exists, it never outputs a message to any device. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * LoggerAppenderEcho uses {@link PHP_MANUAL#echo echo} function to output events. + * + *This appender requires a layout.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * FileAppender appends log events to a file. + * + * Parameters are ({@link $fileName} but option name is file), + * {@link $append}. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLevel.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Log events using php {@link PHP_MANUAL#syslog} function. + * + * Levels are mapped as follows: + * - level >= FATAL to LOG_ALERT + * - FATAL > level >= ERROR to LOG_ERR + * - ERROR > level >= WARN to LOG_WARNING + * - WARN > level >= INFO to LOG_INFO + * - INFO > level >= DEBUG to LOG_DEBUG + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + + +define('LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT', 'php://stdout'); +define('LOG4PHP_LOGGER_APPENDER_CONSOLE_STDERR', 'php://stderr'); + +/** + * ConsoleAppender appends log events to STDOUT or STDERR using a layout specified by the user. + * + *Optional parameter is {@link $target}. The default target is Stdout.
+ *Note: Use this Appender with command-line php scripts. + * On web scripts this appender has no effects.
+ *This appender requires a layout.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/appenders/LoggerAppenderFile.php'); + +/** + * LoggerAppenderDailyFile appends log events to a file ne. + * + * A formatted version of the date pattern is used as to create the file name + * using the {@link PHP_MANUAL#sprintf} function. + *Parameters are {@link $datePattern}, {@link $file}. Note that file + * parameter should include a '%s' identifier and should always be set + * before {@link $file} param.
+ * + * @author Abel GonzalezDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage appenders + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php'); +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +/** + * Appends log events to mail using php function {@link PHP_MANUAL#mail}. + * + *Parameters are {@link $from}, {@link $to}, {@link $subject}.
+ *This appender requires a layout.
+ * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + * Abstract class that defines output logs strategies. + * + * @author VxRIf this method returns true, meaning that layout is required, + * then the configurator will configure a layout using the configuration + * information at its disposal. If this method returns false, + * meaning that a layout is not required, then layout configuration will be + * skipped even if there is available layout configuration + * information at the disposal of the configurator.
+ * + *In the rather exceptional case, where the appender + * implementation admits a layout but can also work without it, then + * the appender should return true.
+ * + * @return boolean + */ + function requiresLayout() + { + // override me + } + +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/LoggerAppenderSkeleton.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/LoggerAppenderSkeleton.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/LoggerAppenderSkeleton.php (revision 18220) @@ -0,0 +1,354 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details). + *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerAppender.php'); +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerFilter.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerLoggingEvent.php'); +require_once(LOG4PHP_DIR . '/helpers/LoggerOptionConverter.php'); + +/** + * Abstract superclass of the other appenders in the package. + * + * This class provides the code for common functionality, such as + * support for threshold filtering and support for general filters. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + + +define('LOGGER_MDC_HT_SIZE', 7); + +/** + * This is the global repository of user mappings + */ +$GLOBALS['log4php.LoggerMDC.ht'] = array(); + +/** + * The LoggerMDC class is similar to the {@link LoggerNDC} class except that it is + * based on a map instead of a stack. It provides mapped diagnostic contexts. + * + * A Mapped Diagnostic Context, or + * MDC in short, is an instrument for distinguishing interleaved log + * output from different sources. Log output is typically interleaved + * when a server handles multiple clients near-simultaneously. + * + *The MDC is managed on a per thread basis.
+ *
+ * @author VxR If the current thread does not have a context map it is
+ * created as a side effect. Note that you cannot put more than {@link LOGGER_MDC_HT_SIZE} keys. You can use special key identifiers to map values in
+ * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.'
+ * followed by the var name you want to refer. This method has no side effects.
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +require_once(LOG4PHP_DIR . '/spi/LoggerConfigurator.php'); +require_once(LOG4PHP_DIR . '/LoggerLayout.php'); +require_once(LOG4PHP_DIR . '/LoggerAppender.php'); +require_once(LOG4PHP_DIR . '/LoggerManager.php'); + +/** + * Use this class to quickly configure the package. + * + *For file based configuration see {@link LoggerPropertyConfigurator}. + *
For XML based configuration see {@link LoggerDOMConfigurator}.
+ *
+ * @author VxR
+ * LoggerManager::resetConfiguration();
+ *
+ *
+ * @see LoggerHierarchy::resetConfiguration()
+ * @static
+ */
+ function resetConfiguration()
+ {
+ LoggerManager::resetConfiguration();
+ }
+}
+?>
Index: branches/comu-ver2/data/module/log4php/php4/log4php/LoggerNDC.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php4/log4php/LoggerNDC.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php4/log4php/LoggerNDC.php (revision 18220)
@@ -0,0 +1,240 @@
+This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerLog.php'); + +define('LOGGER_NDC_HT_SIZE', 7); + +/** + * This is the global repository of NDC stack + */ +$GLOBALS['log4php.LoggerNDC.ht'] = array(); + +/** + * This is the max depth of NDC stack + */ +$GLOBALS['log4php.LoggerNDC.maxDepth'] = LOGGER_NDC_HT_SIZE; + + +/** + * The NDC class implements nested diagnostic contexts as + * defined by Neil Harrison in the article "Patterns for Logging + * Diagnostic Messages" part of the book "Pattern Languages of + * Program Design 3" edited by Martin et al. + * + *A Nested Diagnostic Context, or NDC in short, is an instrument + * to distinguish interleaved log output from different sources. Log + * output is typically interleaved when a server handles multiple + * clients near-simultaneously. + * + *
Interleaved log output can still be meaningful if each log entry + * from different contexts had a distinctive stamp. This is where NDCs + * come into play. + * + *
Note that NDCs are managed on a per thread + * basis. NDC operations such as {@link push()}, {@link pop()}, + * {@link clear()}, {@link getDepth()} and {@link setMaxDepth()} + * affect the NDC of the current thread only. NDCs of other + * threads remain unaffected. + * + *
For example, a servlet can build a per client request NDC + * consisting the clients host name and other information contained in + * the the request. Cookies are another source of distinctive + * information. To build an NDC one uses the {@link push()} + * operation.
+ * + * Simply put, + * + * - Contexts can be nested. + * - When entering a context, call + *LoggerNDC::push()
+ * As a side effect, if there is no nested diagnostic context for the
+ * current thread, this method will create it.
+ * - When leaving a context, call
+ * LoggerNDC::pop()
+ * - When exiting a thread make sure to call {@link remove()}
+ *
+ * There is no penalty for forgetting to match each
+ * push
operation with a corresponding pop
,
+ * except the obvious mismatch between the real application context
+ * and the context set in the NDC.
If configured to do so, {@link LoggerPatternLayout} and {@link LoggerLayoutTTCC} + * instances automatically retrieve the nested diagnostic + * context for the current thread without any user intervention. + * Hence, even if a servlet is serving multiple clients + * simultaneously, the logs emanating from the same code (belonging to + * the same category) can still be distinguished because each client + * request will have a different NDC tag.
+ * + * + * @author VxRThis method is equivalent to calling the {@link setMaxDepth()} + * method with a zero maxDepth argument. + * + * @static + */ + function clear() + { + LoggerLog::debug("LoggerNDC::clear()"); + + $GLOBALS['log4php.LoggerNDC.ht'] = array(); + } + + /** + * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. + * @static + * @return array + */ + function get() + { + LoggerLog::debug("LoggerNDC::get()"); + + return $GLOBALS['log4php.LoggerNDC.ht']; + } + + /** + * Get the current nesting depth of this diagnostic context. + * + * @see setMaxDepth() + * @return integer + * @static + */ + function getDepth() + { + LoggerLog::debug("LoggerNDC::getDepth()"); + + return sizeof($GLOBALS['log4php.LoggerNDC.ht']); + } + + /** + * Clients should call this method before leaving a diagnostic + * context. + * + *
The returned value is the value that was pushed last. If no + * context is available, then the empty string "" is returned.
+ * + * @return string The innermost diagnostic context. + * @static + */ + function pop() + { + LoggerLog::debug("LoggerNDC::pop()"); + + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) { + return array_pop($GLOBALS['log4php.LoggerNDC.ht']); + } else { + return ''; + } + } + + /** + * Looks at the last diagnostic context at the top of this NDC + * without removing it. + * + *The returned value is the value that was pushed last. If no + * context is available, then the empty string "" is returned.
+ * @return string The innermost diagnostic context. + * @static + */ + function peek() + { + LoggerLog::debug("LoggerNDC::peek()"); + + if (sizeof($GLOBALS['log4php.LoggerNDC.ht']) > 0) { + return end($GLOBALS['log4php.LoggerNDC.ht']); + } else { + return ''; + } + } + + /** + * Push new diagnostic context information for the current thread. + * + *The contents of the message parameter is + * determined solely by the client. + * + * @param string $message The new diagnostic context information. + * @static + */ + function push($message) + { + LoggerLog::debug("LoggerNDC::push()"); + + array_push($GLOBALS['log4php.LoggerNDC.ht'], (string)$message); + } + + /** + * Remove the diagnostic context for this thread. + * @static + */ + function remove() + { + LoggerLog::debug("LoggerNDC::remove()"); + + LoggerNDC::clear(); + } + + /** + * Set maximum depth of this diagnostic context. If the current + * depth is smaller or equal to maxDepth, then no + * action is taken. + * + *
This method is a convenient alternative to multiple + * {@link pop()} calls. Moreover, it is often the case that at + * the end of complex call sequences, the depth of the NDC is + * unpredictable. The {@link setMaxDepth()} method circumvents + * this problem. + * + * @param integer $maxDepth + * @see getDepth() + * @static + */ + function setMaxDepth($maxDepth) + { + LoggerLog::debug("LoggerNDC::setMaxDepth() maxDepth='$maxDepth'"); + + $maxDepth = (int)$maxDepth; + if ($maxDepth <= LOGGER_NDC_HT_SIZE) { + if (LoggerNDC::getDepth() > $maxDepth) { + $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth); + } + $GLOBALS['log4php.LoggerNDC.maxDepth'] = $maxDepth; + } + } + +} +?> Index: branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFilter.php =================================================================== --- branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFilter.php (revision 18220) +++ branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFilter.php (revision 18220) @@ -0,0 +1,118 @@ +This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
+ *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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage spi + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/spi/LoggerLoggingEvent.php'); + + +/** + * The log event must be logged immediately without consulting with + * the remaining filters, if any, in the chain. + */ +define('LOG4PHP_LOGGER_FILTER_ACCEPT', 1); + +/** + * This filter is neutral with respect to the log event. The + * remaining filters, if any, should be consulted for a final decision. + */ +define('LOG4PHP_LOGGER_FILTER_NEUTRAL', 0); + +/** + * The log event must be dropped immediately without consulting + * with the remaining filters, if any, in the chain. + */ +define('LOG4PHP_LOGGER_FILTER_DENY', -1); + +/** + * Users should extend this class to implement customized logging + * event filtering. Note that {@link LoggerCategory} and {@link LoggerAppenderSkeleton}, + * the parent class of all standard + * appenders, have built-in filtering rules. It is suggested that you + * first use and understand the built-in rules before rushing to write + * your own custom filters. + * + *This abstract class assumes and also imposes that filters be + * organized in a linear chain. The {@link #decide + * decide(LoggerLoggingEvent)} method of each filter is called sequentially, + * in the order of their addition to the chain. + * + *
The {@link decide()} method must return one + * of the integer constants {@link LOG4PHP_LOG4PHP_LOGGER_FILTER_DENY}, + * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_ACCEPT}. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_DENY} is returned, then the log event is + * dropped immediately without consulting with the remaining + * filters. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned, then the next filter + * in the chain is consulted. If there are no more filters in the + * chain, then the log event is logged. Thus, in the presence of no + * filters, the default behaviour is to log all logging events. + * + *
If the value {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, then the log + * event is logged without consulting the remaining filters. + * + *
The philosophy of log4php filters is largely inspired from the
+ * Linux ipchains.
+ *
+ * @author VxR If the decision is {@link LOG4PHP_LOGGER_FILTER_DENY}, then the event will be
+ * dropped. If the decision is {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}, then the next
+ * filter, if any, will be invoked. If the decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} then
+ * the event will be logged without consulting with other filters in
+ * the chain.
+ *
+ * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to decide upon.
+ * @return integer {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_DENY}|{@link LOG4PHP_LOGGER_FILTER_ACCEPT}
+ */
+ function decide($event)
+ {
+ return LOG4PHP_LOGGER_FILTER_NEUTRAL;
+ }
+
+}
+?>
Index: branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFactory.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFactory.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerFactory.php (revision 18220)
@@ -0,0 +1,53 @@
+This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details). 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}). PHP port, extensions and modifications by VxR. All rights reserved. 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.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage spi + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + */ +require_once(LOG4PHP_DIR . '/LoggerManager.php'); +require_once(LOG4PHP_DIR . '/LoggerMDC.php'); +require_once(LOG4PHP_DIR . '/LoggerNDC.php'); +require_once(LOG4PHP_DIR . '/spi/LoggerLocationInfo.php'); + +LoggerLoggingEvent::getStartTime(); + +/** + * The internal representation of logging event. + * + * @author VxRThis field should not be accessed directly. You shoud use the + * {@link getLevel()} method instead. + * + * @deprecated + * @var LoggerLevel + */ + var $level; + + /** + * @var string The nested diagnostic context (NDC) of logging event. + */ + var $ndc; + + /** + * Have we tried to do an NDC lookup? If we did, there is no need + * to do it again. Note that its value is always false when + * serialized. Thus, a receiving SocketNode will never use it's own + * (incorrect) NDC. See also writeObject method. + * @var boolean + */ + var $ndcLookupRequired = true; + + /** + * Have we tried to do an MDC lookup? If we did, there is no need + * to do it again. Note that its value is always false when + * serialized. See also the getMDC and getMDCCopy methods. + * @var boolean + */ + var $mdcCopyLookupRequired = true; + + /** + * @var mixed The application supplied message of logging event. + */ + var $message; + + /** + * The application supplied message rendered through the log4php + * objet rendering mechanism. At present renderedMessage == message. + * @var string + */ + var $renderedMessage; + + /** + * The name of thread in which this logging event was generated. + * log4php saves here the process id via {@link PHP_MANUAL#getmypid getmypid()} + * @var mixed + */ + var $threadName = null; + + /** + * The number of seconds elapsed from 1/1/1970 until logging event + * was created plus microseconds if available. + * @var float + */ + var $timeStamp; + + /** + * @var LoggerLocationInfo Location information for the caller. + */ + var $locationInfo = null; + + // Serialization + /* + var $serialVersionUID = -868428216207166145L; + var $PARAM_ARRAY = array(); + var $TO_LEVEL = "toLevel"; + var $TO_LEVEL_PARAMS = null; + var $methodCache = array(); // use a tiny table + */ + + /** + * Instantiate a LoggingEvent from the supplied parameters. + * + *
Except {@link $timeStamp} all the other fields of + * LoggerLoggingEvent are filled when actually needed. + * + * @param string $fqcn name of the caller class. + * @param Logger &$logger The category of this event. + * @param integer $level The level of this event. + * @param mixed $message The message of this event. + * @param integer $timeStamp the timestamp of this logging event. + * @param integer $timeStampMSecs the timestamp milliseconds of this logging event. + */ + function LoggerLoggingEvent($fqcn, &$logger, $priority, $message, $timeStamp = null) + { + $this->fqcn = $fqcn; + if (is_a($logger, 'logger')) { + $this->logger =& $logger; + $this->categoryName = $logger->getName(); + } else { + $this->categoryName = (string)$logger; + } + $this->level = $priority; + $this->message = $message; + if ($timeStamp !== null and is_float($timeStamp)) { + $this->timeStamp = $timeStamp; + } else { + if (function_exists('microtime')) { + list($usecs, $secs) = explode(' ', microtime()); + $this->timeStamp = ((float)$usecs + (float)$secs); + } else { + $this->timeStamp = time(); + } + } + } + + /** + * Set the location information for this logging event. The collected + * information is cached for future use. + * + *
This method uses {@link PHP_MANUAL#debug_backtrace debug_backtrace()} function (if exists) + * to collect informations about caller.
+ *It only recognize informations generated by {@link Logger} and its subclasses.
+ * @return LoggerLocationInfo + */ + function getLocationInformation() + { + if($this->locationInfo === null) { + + $locationInfo = array(); + + if (function_exists('debug_backtrace')) { + $trace = debug_backtrace(); + $prevHop = null; + // make a downsearch to identify the caller + $hop = array_pop($trace); + while ($hop !== null) { + $className = @$hop['class']; + if ( !empty($className) and ($className == 'logger' or get_parent_class($className) == 'logger') ) { + $locationInfo['line'] = $hop['line']; + $locationInfo['file'] = $hop['file']; + break; + } + $prevHop = $hop; + $hop = array_pop($trace); + } + $locationInfo['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main'; + if (isset($prevHop['function']) and + $prevHop['function'] !== 'include' and + $prevHop['function'] !== 'include_once' and + $prevHop['function'] !== 'require' and + $prevHop['function'] !== 'require_once') { + + $locationInfo['function'] = $prevHop['function']; + } else { + $locationInfo['function'] = 'main'; + } + } + + $this->locationInfo = new LoggerLocationInfo($locationInfo, $this->fqcn); + } + return $this->locationInfo; + } + + /** + * Return the level of this event. Use this form instead of directly + * accessing the {@link $level} field. + * @return LoggerLevel + */ + function getLevel() + { + return $this->level; + } + + /** + * Return the name of the logger. Use this form instead of directly + * accessing the {@link $categoryName} field. + * @return string + */ + function getLoggerName() + { + return $this->categoryName; + } + + /** + * Return the message for this logging event. + * + *Before serialization, the returned object is the message
+ * passed by the user to generate the logging event. After
+ * serialization, the returned value equals the String form of the
+ * message possibly after object rendering.
+ * @return mixed
+ */
+ function getMessage()
+ {
+ if($this->message !== null) {
+ return $this->message;
+ } else {
+ return $this->getRenderedMessage();
+ }
+ }
+
+ /**
+ * This method returns the NDC for this event. It will return the
+ * correct content even if the event was generated in a different
+ * thread or even on a different machine. The {@link LoggerNDC::get()} method
+ * should never be called directly.
+ * @return string
+ */
+ function getNDC()
+ {
+ if ($this->ndcLookupRequired) {
+ $this->ndcLookupRequired = false;
+ $this->ndc = implode(' ',LoggerNDC::get());
+ }
+ return $this->ndc;
+ }
+
+
+ /**
+ * Returns the the context corresponding to the key
+ * parameter.
+ * @return string
+ */
+ function getMDC($key)
+ {
+ return LoggerMDC::get($key);
+ }
+
+ /**
+ * Render message.
+ * @return string
+ */
+ function getRenderedMessage()
+ {
+ if($this->renderedMessage === null and $this->message !== null) {
+ if (is_string($this->message)) {
+ $this->renderedMessage = $this->message;
+ } else {
+ if ($this->logger !== null) {
+ $repository =& $this->logger->getLoggerRepository();
+ } else {
+ $repository =& LoggerManager::getLoggerRepository();
+ }
+ if (method_exists($repository, 'getrenderermap')) {
+ $rendererMap =& $repository->getRendererMap();
+ $this->renderedMessage= $rendererMap->findAndRender($this->message);
+ } else {
+ $this->renderedMessage = (string)$this->message;
+ }
+ }
+ }
+ return $this->renderedMessage;
+ }
+
+ /**
+ * Returns the time when the application started, in seconds
+ * elapsed since 01.01.1970 plus microseconds if available.
+ *
+ * @return float
+ * @static
+ */
+ function getStartTime()
+ {
+ static $startTime;
+
+ if (!isset($startTime)) {
+ if (function_exists('microtime')) {
+ list($usec, $sec) = explode(' ', microtime());
+ $startTime = ((float)$usec + (float)$sec);
+ } else {
+ $startTime = time();
+ }
+ }
+ return $startTime;
+ }
+
+ /**
+ * @return float
+ */
+ function getTimeStamp()
+ {
+ return $this->timeStamp;
+ }
+
+ /**
+ * @return mixed
+ */
+ function getThreadName()
+ {
+ if ($this->threadName === null)
+ $this->threadName = (string)getmypid();
+ return $this->threadName;
+ }
+
+ /**
+ * @return mixed null
+ */
+ function getThrowableInformation()
+ {
+ return null;
+ }
+
+ /**
+ * Serialize this object
+ * @return string
+ */
+ function toString()
+ {
+ serialize($this);
+ }
+
+ /**
+ * Avoid serialization of the {@link $logger} object
+ */
+ function __sleep()
+ {
+ return array(
+ 'fqcn','categoryName',
+ 'level',
+ 'ndc','ndcLookupRequired',
+ 'message','renderedMessage',
+ 'threadName',
+ 'timestamp',
+ 'locationInfo'
+ );
+ }
+
+}
+?>
Index: branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerConfigurator.php
===================================================================
--- branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerConfigurator.php (revision 18220)
+++ branches/comu-ver2/data/module/log4php/php4/log4php/spi/LoggerConfigurator.php (revision 18220)
@@ -0,0 +1,65 @@
+This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).
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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage spi + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__)); + +/** + * Special level value signifying inherited behaviour. The current + * value of this string constant is inherited. + * {@link LOG4PHP_LOGGER_CONFIGURATOR_NULL} is a synonym. + */ +define('LOG4PHP_LOGGER_CONFIGURATOR_INHERITED', 'inherited'); + +/** + * Special level signifying inherited behaviour, same as + * {@link LOG4PHP_LOGGER_CONFIGURATOR_INHERITED}. + * The current value of this string constant is null. + */ +define('LOG4PHP_LOGGER_CONFIGURATOR_NULL', 'null'); + +/** + * Implemented by classes capable of configuring log4php using a URL. + * + * @author VxRDesign, 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}).
+ * + *PHP port, extensions and modifications by VxR. All rights reserved.
+ * For more information, please see {@link http://www.vxr.it/log4php/}.
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.
+ * + * @package log4php + * @subpackage spi + */ + +/** + * @ignore + */ +if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); + +/** + * When location information is not available the constant + * NA is returned. Current value of this string + * constant is ?. + */ +define('LOG4PHP_LOGGER_LOCATION_INFO_NA', 'NA'); + +/** + * The internal representation of caller location information. + * + * @author VxRThis information is not always available. + */ + function getFileName() + { + return ($this->fileName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->fileName; + } + + /** + * Returns the line number of the caller. + *
This information is not always available. + */ + function getLineNumber() + { + return ($this->lineNumber === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->lineNumber; + } + + /** + * Returns the method name of the caller. + */ + function getMethodName() + { + return ($this->methodName === null) ? LOG4PHP_LOGGER_LOCATION_INFO_NA : $this->methodName; + } +} +?> Index: branches/comu-ver2/test/class/logger/GC_Log_Log4php_Test.php =================================================================== --- branches/comu-ver2/test/class/logger/GC_Log_Log4php_Test.php (revision 18220) +++ branches/comu-ver2/test/class/logger/GC_Log_Log4php_Test.php (revision 18220) @@ -0,0 +1,118 @@ +gfDebug('DEBUGログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[DEBUG] DEBUGログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * INFOログのテスト + * + * + */ + function testGfInfo(){ + $object = new GC_Log_Log4php(); + + ob_start(); + $object->gfInfo('INFOログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[INFO] INFOログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * ERRORログのテスト + * + * + */ + function testGfError(){ + $object = new GC_Log_Log4php(); + + ob_start(); + $object->gfError('ERRORログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[ERROR] ERRORログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * FATALログのテスト + * + * + */ + function testGfFatal(){ + $object = new GC_Log_Log4php(); + + ob_start(); + $object->gfFatal('FATALログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[FATAL] FATALログ\n"; + + $this->assertEquals($buff, $output); + } +} +?> Index: branches/comu-ver2/test/class/logger/GC_Logger_Test.php =================================================================== --- branches/comu-ver2/test/class/logger/GC_Logger_Test.php (revision 18220) +++ branches/comu-ver2/test/class/logger/GC_Logger_Test.php (revision 18220) @@ -0,0 +1,228 @@ +assertSame($object1, $object2); + + $object3 = GC_Logger::gfGetInstance('logger3'); + $object4 = GC_Logger::gfGetInstance('logger4'); + + $this->assertNotSame($object3, $object4); + } + + /** + * DEBUGログのテスト + * + * + */ + function testGfDebug(){ + $object = GC_Logger::gfGetInstance(); + + ob_start(); + $object->gfDebug('DEBUGログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[DEBUG] DEBUGログ\n"; + + $this->assertEquals($buff,$output); + } + + /** + * DEBUGログ、ダンプテスト + * + * + */ + function testGfDebugDump(){ + $object = GC_Logger::gfGetInstance(); + $a = array('test'); + ob_start(); + $object->gfDebug('a => ', $a); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = +"[DEBUG] a => Array +( + [0] => test +) + +"; + $this->assertEquals($buff,$output); + } + + /** + * INFOログのテスト + * + * + */ + function testGfInfo(){ + $object = GC_Logger::gfGetInstance(); + + ob_start(); + $object->gfInfo('INFOログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[INFO] INFOログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * INFOログ、ダンプのテスト + * + * + */ + function testGfInfoDump(){ + $object = GC_Logger::gfGetInstance(); + $a = array('test'); + ob_start(); + $object->gfInfo('a => ', $a); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = +"[INFO] a => Array +( + [0] => test +) + +"; + $this->assertEquals($buff, $output); + } + + /** + * ERRORログのテスト + * + * + */ + function testGfError(){ + $object = GC_Logger::gfGetInstance(); + + ob_start(); + $object->gfError('ERRORログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[ERROR] ERRORログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * ERRORログ、ダンプのテスト + * + * + */ + function testGfErrorDump(){ + $object = GC_Logger::gfGetInstance(); + $a = array('test'); + ob_start(); + $object->gfError('a => ', $a); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = +"[ERROR] a => Array +( + [0] => test +) + +"; + $this->assertEquals($buff, $output); + } + + /** + * FATALログのテスト + * + * + */ + function testGfFatal(){ + $object = GC_Logger::gfGetInstance(); + + ob_start(); + $object->gfFatal('FATALログ'); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = "[FATAL] FATALログ\n"; + + $this->assertEquals($buff, $output); + } + + /** + * FATALログ、ダンプのテスト + * + * + */ + function testGfFatalDump(){ + $object = GC_Logger::gfGetInstance(); + $a = array('test'); + ob_start(); + $object->gfFatal('a => ', $a); + $buff = ob_get_contents(); + ob_end_clean(); + + $output = +"[FATAL] a => Array +( + [0] => test +) + +"; + $this->assertEquals($buff, $output); + } +} +?> Index: branches/comu-ver2/test/class/logger/conf/log4php.properties =================================================================== --- branches/comu-ver2/test/class/logger/conf/log4php.properties (revision 18220) +++ branches/comu-ver2/test/class/logger/conf/log4php.properties (revision 18220) @@ -0,0 +1,7 @@ +#--------------------------------- +# root logger test +#--------------------------------- +log4php.rootLogger=DEBUG, R +log4php.appender.R=LoggerAppenderEcho +log4php.appender.R.layout=LoggerPatternLayout +log4php.appender.R.layout.ConversionPattern="[%p] %m%n"