[Vtigercrm-commits] [vtiger-commits] r5732 - in /vtigercrm/trunk/log4php/helpers: LoggerFormattingInfo.php LoggerOptionConverter.php LoggerPatternConverter.php LoggerPatternParser.php LoggerTransform.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Thu May 4 00:11:30 EDT 2006


Author: saraj
Date: Wed May  3 22:11:21 2006
New Revision: 5732

Log:
log4php latest version has been updated

Modified:
    vtigercrm/trunk/log4php/helpers/LoggerFormattingInfo.php
    vtigercrm/trunk/log4php/helpers/LoggerOptionConverter.php
    vtigercrm/trunk/log4php/helpers/LoggerPatternConverter.php
    vtigercrm/trunk/log4php/helpers/LoggerPatternParser.php
    vtigercrm/trunk/log4php/helpers/LoggerTransform.php

Modified: vtigercrm/trunk/log4php/helpers/LoggerFormattingInfo.php
==============================================================================
--- vtigercrm/trunk/log4php/helpers/LoggerFormattingInfo.php (original)
+++ vtigercrm/trunk/log4php/helpers/LoggerFormattingInfo.php Wed May  3 22:11:21 2006
@@ -1,61 +1,61 @@
-<?php
-/**
- * log4php is a PHP port of the log4j java logging package.
- * 
- * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
- * <p>Design, strategies and part of the methods documentation are developed by log4j team 
- * (Ceki Gülcü as log4j project founder and 
- * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
- *
- * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
- * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
- *
- * <p>This software is published under the terms of the LGPL License
- * a copy of which has been included with this distribution in the LICENSE file.</p>
- * 
- * @package log4php
- * @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 VxR <vxr at vxr.it>
- * @package log4php
- * @subpackage spi
- * @since 0.3
- */
-class LoggerFormattingInfo {
-
-    var $min        = -1;
-    var $max        = 0x7FFFFFFF;
-    var $leftAlign  = false;
-
-    /**
-     * Constructor
-     */
-    function LoggerFormattingInfo() {}
-    
-    function reset()
-    {
-        $this->min          = -1;
-        $this->max          = 0x7FFFFFFF;
-        $this->leftAlign    = false;      
-    }
-
-    function dump()
-    {
-        LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}");
-    }
-} 
+<?php
+/**
+ * log4php is a PHP port of the log4j java logging package.
+ * 
+ * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
+ * <p>Design, strategies and part of the methods documentation are developed by log4j team 
+ * (Ceki Gülcü as log4j project founder and 
+ * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
+ *
+ * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
+ * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
+ *
+ * <p>This software is published under the terms of the LGPL License
+ * a copy of which has been included with this distribution in the LICENSE file.</p>
+ * 
+ * @package log4php
+ * @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 VxR <vxr at vxr.it>
+ * @package log4php
+ * @subpackage spi
+ * @since 0.3
+ */
+class LoggerFormattingInfo {
+
+    var $min        = -1;
+    var $max        = 0x7FFFFFFF;
+    var $leftAlign  = false;
+
+    /**
+     * Constructor
+     */
+    function LoggerFormattingInfo() {}
+    
+    function reset()
+    {
+        $this->min          = -1;
+        $this->max          = 0x7FFFFFFF;
+        $this->leftAlign    = false;      
+    }
+
+    function dump()
+    {
+        LoggerLog::debug("LoggerFormattingInfo::dump() min={$this->min}, max={$this->max}, leftAlign={$this->leftAlign}");
+    }
+} 
 ?>

Modified: vtigercrm/trunk/log4php/helpers/LoggerOptionConverter.php
==============================================================================
--- vtigercrm/trunk/log4php/helpers/LoggerOptionConverter.php (original)
+++ vtigercrm/trunk/log4php/helpers/LoggerOptionConverter.php Wed May  3 22:11:21 2006
@@ -1,350 +1,350 @@
-<?php
-/**
- * log4php is a PHP port of the log4j java logging package.
- * 
- * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
- * <p>Design, strategies and part of the methods documentation are developed by log4j team 
- * (Ceki Gülcü as log4j project founder and 
- * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
- *
- * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
- * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
- *
- * <p>This software is published under the terms of the LGPL License
- * a copy of which has been included with this distribution in the LICENSE file.</p>
- * 
- * @package log4php
- * @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 VxR <vxr at vxr.it>
- * @version $Revision: 1.1 $ 
- * @package log4php
- * @subpackage helpers
- * @static
- * @since 0.5
- */
-class LoggerOptionConverter {
-
-    /** 
-     * OptionConverter is a static class. 
-     */
-    function OptionConverter() 
-    {
-        return;
-    }
-
-    /**
-     * @param array $l
-     * @param array $r
-     * @return array
-     *
-     * @static
-     */
-    function concatanateArrays($l, $r)
-    {
-        return array_merge($l, $r);
-    }
-
-    /**
-    * Read a predefined var.
-    *
-    * It returns a value referenced by <var>$key</var> using this search criteria:
-    * - if <var>$key</var> is a constant then return it. Else
-    * - if <var>$key</var> is set in <var>$_ENV</var> then return it. Else
-    * - return <var>$def</var>. 
-    *
-    * @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
-    */
-    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 <var>$value</var> is <i>true</i>, then <i>true</i> is
-     * returned. If <var>$value</var> is <i>false</i>, then
-     * <i>true</i> is returned. Otherwise, <var>$default</var> is
-     * returned.
-     *
-     * <p>Case of value is unimportant.</p>
-     *
-     * @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.
-     *
-     * <p> If <var>$value</var> is of form "<b>level#full_file_classname</b>",
-     * where <i>full_file_classname</i> means the class filename with path
-     * but without php extension, then the specified class' <i>toLevel()</i> 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.</p>
-     *
-     * <p>As a special case, if the <var>$value</var> parameter is
-     * equal to the string "NULL", then the value <i>null</i> will
-     * be returned.</p>
-     *
-     * <p>If any error occurs while converting the value to a level,
-     * the <var>$defaultValue</var> parameter, which may be
-     * <i>null</i>, is returned.</p>
-     *
-     * <p>Case of <var>$value</var> is insignificant for the level level, but is
-     * significant for the class name part, if present.</p>
-     *
-     * @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 <var>$key</var> in
-     * <var>$props</var>. 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 <var>$val</var> from the
-     * values of keys found with the {@link getSystemProperty()} method.
-     * 
-     * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>.
-     * 
-     * <p>For example, if the "MY_CONSTANT" contains "value", then
-     * the call
-     * <code>
-     * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}.");
-     * </code>
-     * will set the variable <i>$s</i> to "Value of key is value.".</p>
-     * 
-     * <p>If no value could be found for the specified key, then the
-     * <var>$props</var> parameter is searched, if the value could not
-     * be found there, then substitution defaults to the empty string.</p>
-     * 
-     * <p>For example, if {@link getSystemProperty()} cannot find any value for the key
-     * "inexistentKey", then the call
-     * <code>
-     * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
-     * </code>
-     * will set <var>$s</var> to "Value of inexistentKey is []".</p>
-     * 
-     * <p>A warn is thrown if <var>$val</var> contains a start delimeter "${" 
-     * which is not balanced by a stop delimeter "}" and an empty string is returned.</p>
-     * 
-     * @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;
-	            }
-            }
-        }
-    }
-
-}
+<?php
+/**
+ * log4php is a PHP port of the log4j java logging package.
+ * 
+ * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
+ * <p>Design, strategies and part of the methods documentation are developed by log4j team 
+ * (Ceki Gülcü as log4j project founder and 
+ * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
+ *
+ * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
+ * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
+ *
+ * <p>This software is published under the terms of the LGPL License
+ * a copy of which has been included with this distribution in the LICENSE file.</p>
+ * 
+ * @package log4php
+ * @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 VxR <vxr at vxr.it>
+ * @version $Revision: 1.6 $ 
+ * @package log4php
+ * @subpackage helpers
+ * @static
+ * @since 0.5
+ */
+class LoggerOptionConverter {
+
+    /** 
+     * OptionConverter is a static class. 
+     */
+    function OptionConverter() 
+    {
+        return;
+    }
+
+    /**
+     * @param array $l
+     * @param array $r
+     * @return array
+     *
+     * @static
+     */
+    function concatanateArrays($l, $r)
+    {
+        return array_merge($l, $r);
+    }
+
+    /**
+    * Read a predefined var.
+    *
+    * It returns a value referenced by <var>$key</var> using this search criteria:
+    * - if <var>$key</var> is a constant then return it. Else
+    * - if <var>$key</var> is set in <var>$_ENV</var> then return it. Else
+    * - return <var>$def</var>. 
+    *
+    * @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
+    */
+    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 <var>$value</var> is <i>true</i>, then <i>true</i> is
+     * returned. If <var>$value</var> is <i>false</i>, then
+     * <i>true</i> is returned. Otherwise, <var>$default</var> is
+     * returned.
+     *
+     * <p>Case of value is unimportant.</p>
+     *
+     * @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.
+     *
+     * <p> If <var>$value</var> is of form "<b>level#full_file_classname</b>",
+     * where <i>full_file_classname</i> means the class filename with path
+     * but without php extension, then the specified class' <i>toLevel()</i> 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.</p>
+     *
+     * <p>As a special case, if the <var>$value</var> parameter is
+     * equal to the string "NULL", then the value <i>null</i> will
+     * be returned.</p>
+     *
+     * <p>If any error occurs while converting the value to a level,
+     * the <var>$defaultValue</var> parameter, which may be
+     * <i>null</i>, is returned.</p>
+     *
+     * <p>Case of <var>$value</var> is insignificant for the level level, but is
+     * significant for the class name part, if present.</p>
+     *
+     * @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 <var>$key</var> in
+     * <var>$props</var>. 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 <var>$val</var> from the
+     * values of keys found with the {@link getSystemProperty()} method.
+     * 
+     * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>.
+     * 
+     * <p>For example, if the "MY_CONSTANT" contains "value", then
+     * the call
+     * <code>
+     * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}.");
+     * </code>
+     * will set the variable <i>$s</i> to "Value of key is value.".</p>
+     * 
+     * <p>If no value could be found for the specified key, then the
+     * <var>$props</var> parameter is searched, if the value could not
+     * be found there, then substitution defaults to the empty string.</p>
+     * 
+     * <p>For example, if {@link getSystemProperty()} cannot find any value for the key
+     * "inexistentKey", then the call
+     * <code>
+     * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]");
+     * </code>
+     * will set <var>$s</var> to "Value of inexistentKey is []".</p>
+     * 
+     * <p>A warn is thrown if <var>$val</var> contains a start delimeter "${" 
+     * which is not balanced by a stop delimeter "}" and an empty string is returned.</p>
+     * 
+     * @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;
+	            }
+            }
+        }
+    }
+
+}
 ?>

Modified: vtigercrm/trunk/log4php/helpers/LoggerPatternConverter.php
==============================================================================
--- vtigercrm/trunk/log4php/helpers/LoggerPatternConverter.php (original)
+++ vtigercrm/trunk/log4php/helpers/LoggerPatternConverter.php Wed May  3 22:11:21 2006
@@ -1,504 +1,504 @@
-<?php
-/**
- * log4php is a PHP port of the log4j java logging package.
- * 
- * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
- * <p>Design, strategies and part of the methods documentation are developed by log4j team 
- * (Ceki Gülcü as log4j project founder and 
- * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
- *
- * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
- * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
- *
- * <p>This software is published under the terms of the LGPL License
- * a copy of which has been included with this distribution in the LICENSE file.</p>
- * 
- * @package log4php
- * @subpackage helpers
- */
-
-/**
- * @ignore 
- */
-if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
-
-/**
- */
-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.
- * 
- * <p>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.</p>
- * 
- * @author VxR <vxr at vxr.it>
- * @version $Revision: 1.1 $
- * @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 VxR <vxr at vxr.it>
- * @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 VxR <vxr at vxr.it>
- * @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 VxR <vxr at vxr.it>
- * @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 = str_replace("\u", "u", ereg_replace("[^\\]u", sprintf(',%03d', $usecs), $this->df));
-         
-        return date($this->df, $event->getTimeStamp());
-        
-    }
-}
-
-/**
- * @author VxR <vxr at vxr.it>
- * @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 VxR <vxr at vxr.it>
- * @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->fullInfo;
-            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 VxR <vxr at vxr.it>
- * @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 VxR <vxr at vxr.it>
- * @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 VxR <vxr at vxr.it>
- * @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();
-    }
-}
-
+<?php
+/**
+ * log4php is a PHP port of the log4j java logging package.
+ * 
+ * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
+ * <p>Design, strategies and part of the methods documentation are developed by log4j team 
+ * (Ceki Gülcü as log4j project founder and 
+ * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
+ *
+ * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
+ * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
+ *
+ * <p>This software is published under the terms of the LGPL License
+ * a copy of which has been included with this distribution in the LICENSE file.</p>
+ * 
+ * @package log4php
+ * @subpackage helpers
+ */
+
+/**
+ * @ignore 
+ */
+if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
+
+/**
+ */
+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.
+ * 
+ * <p>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.</p>
+ * 
+ * @author VxR <vxr at vxr.it>
+ * @version $Revision: 1.13 $
+ * @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 VxR <vxr at vxr.it>
+ * @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 VxR <vxr at vxr.it>
+ * @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 VxR <vxr at vxr.it>
+ * @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 = str_replace("\u", "u", ereg_replace("[^\\]u", sprintf(',%03d', $usecs), $this->df));
+         
+        return date($this->df, $event->getTimeStamp());
+        
+    }
+}
+
+/**
+ * @author VxR <vxr at vxr.it>
+ * @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 VxR <vxr at vxr.it>
+ * @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->fullInfo;
+            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 VxR <vxr at vxr.it>
+ * @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 VxR <vxr at vxr.it>
+ * @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 VxR <vxr at vxr.it>
+ * @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();
+    }
+}
+
 ?>

Modified: vtigercrm/trunk/log4php/helpers/LoggerPatternParser.php
==============================================================================
--- vtigercrm/trunk/log4php/helpers/LoggerPatternParser.php (original)
+++ vtigercrm/trunk/log4php/helpers/LoggerPatternParser.php Wed May  3 22:11:21 2006
@@ -1,419 +1,419 @@
-<?php
-/**
- * log4php is a PHP port of the log4j java logging package.
- * 
- * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
- * <p>Design, strategies and part of the methods documentation are developed by log4j team 
- * (Ceki Gülcü as log4j project founder and 
- * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
- *
- * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
- * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
- *
- * <p>This software is published under the terms of the LGPL License
- * a copy of which has been included with this distribution in the LICENSE file.</p>
- * 
- * @package log4php
- * @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/LoggerFormattingInfo.php');
-require_once(LOG4PHP_DIR . '/helpers/LoggerPatternConverter.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.
- * 
- * <p>It is this class that parses conversion patterns and creates
- * a chained list of {@link LoggerPatternConverter} converters.</p>
- * 
- * @author VxR <vxr at vxr.it>
- * @version $Revision: 1.1 $ 
- * @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->formattingInfo->dump();
-                $this->currentLiteral = '';
-                break;
-            case 'C':
-                $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption());
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() CLASSNAME converter.");
-                //$this->formattingInfo->dump();
-                $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.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'l':
-                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER);
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() Location converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'L':
-                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER);
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() LINE NUMBER converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'm':
-                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER);
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() MESSAGE converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'M':
-                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER);
-                //LogLog.debug("METHOD converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'p':
-                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER);
-                //LogLog.debug("LEVEL converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 'r':
-                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER);
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() RELATIVE TIME converter.");
-                //formattingInfo.dump();
-                $this->currentLiteral = '';
-                break;
-            case 't':
-                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER);
-                LoggerLog::debug("LoggerPatternParser::finalizeConverter() THREAD converter.");
-                //formattingInfo.dump();
-                $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}].");
-	                    // formattingInfo.dump();
-                        $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();
-    }
-}
-
+<?php
+/**
+ * log4php is a PHP port of the log4j java logging package.
+ * 
+ * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
+ * <p>Design, strategies and part of the methods documentation are developed by log4j team 
+ * (Ceki Gülcü as log4j project founder and 
+ * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
+ *
+ * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
+ * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
+ *
+ * <p>This software is published under the terms of the LGPL License
+ * a copy of which has been included with this distribution in the LICENSE file.</p>
+ * 
+ * @package log4php
+ * @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/LoggerFormattingInfo.php');
+require_once(LOG4PHP_DIR . '/helpers/LoggerPatternConverter.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.
+ * 
+ * <p>It is this class that parses conversion patterns and creates
+ * a chained list of {@link LoggerPatternConverter} converters.</p>
+ * 
+ * @author VxR <vxr at vxr.it>
+ * @version $Revision: 1.10 $ 
+ * @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



More information about the vtigercrm-commits mailing list