添加到 trunk

+YUCHENG HU+



git-svn-id: https://svn.code.sf.net/p/hawebs/svn@135 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-06-12 06:29:25 +00:00
parent 6a1cec3fc4
commit 802ea9b607
52 changed files with 10148 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
require_once(LOG4PHP_DIR . '/LoggerCategory.php');
require_once(LOG4PHP_DIR . '/LoggerManager.php');
/**
* Main class for logging operations
*
* @author VxR <[email protected]>
* @version $Revision: 1.9 $
* @package log4php
*/
class Logger extends LoggerCategory {
/**
* Constructor
* @param string $name logger name
*/
function Logger($name)
{
$this->LoggerCategory($name);
}
/**
* 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
*/
function &getLogger($name, $factory = null)
{
return LoggerManager::getLogger($name, $factory);
}
/**
* get the Root Logger (Delegate to {@link LoggerManager})
* @return LoggerRoot
* @static
*/
function &getRootLogger()
{
return LoggerManager::getRootLogger();
}
}
?>
@@ -0,0 +1,218 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
* Abstract class that defines output logs strategies.
*
* @author VxR <[email protected]>
* @version $Revision: 1.14 $
* @package log4php
* @abstract
*/
class LoggerAppender {
/**
* Factory
*
* @param string $name appender name
* @param string $class create an instance of this appender class
* @return LoggerAppender
*/
function factory($name, $class)
{
$class = basename($class);
if (!empty($class)) {
if (!class_exists($class))
@include_once(LOG4PHP_DIR . "/appenders/{$class}.php");
if (class_exists($class))
return new $class($name);
}
return null;
}
/**
* Singleton
*
* @param string $name appender name
* @param string $class create or get a reference instance of this class
* @return LoggerAppender
*/
function &singleton($name, $class = '')
{
static $instances;
if (!empty($name)) {
if (!isset($instances[$name])) {
if (!empty($class)) {
$appender = LoggerAppender::factory($name, $class);
if ($appender !== null) {
$instances[$name] = $appender;
return $instances[$name];
}
}
return null;
}
return $instances[$name];
}
return null;
}
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/**
* Add a filter to the end of the filter list.
*
* @param LoggerFilter $newFilter add a new LoggerFilter
* @abstract
*/
function addFilter($newFilter)
{
// override
}
/**
* Clear the list of filters by removing all the filters in it.
* @abstract
*/
function clearFilters()
{
// override
}
/**
* Return the first filter in the filter chain for this Appender.
* The return value may be <i>null</i> if no is filter is set.
* @return Filter
*/
function &getFilter()
{
// override
}
/**
* Release any resources allocated.
* Subclasses of {@link LoggerAppender} should implement
* this method to perform proper closing procedures.
* @abstract
*/
function close()
{
//override me
}
/**
* This method performs threshold checks and invokes filters before
* delegating actual logging to the subclasses specific <i>append()</i> method.
* @param LoggerLoggingEvent $event
* @abstract
*/
function doAppend($event)
{
//override me
}
/**
* Get the name of this appender.
* @return string
*/
function getName()
{
//override me
}
/**
* Do not use this method.
*
* @param object $errorHandler
*/
function setErrorHandler($errorHandler)
{
// override me
}
/**
* Do not use this method.
* @return object Returns the ErrorHandler for this appender.
*/
function &getErrorHandler()
{
return $this->errorHandler;
}
/**
* Set the Layout for this appender.
*
* @param LoggerLayout $layout
*/
function setLayout($layout)
{
// override me
}
/**
* Returns this appender layout.
* @return LoggerLayout
*/
function &getLayout()
{
// override me
}
/**
* Set the name of this appender.
*
* The name is used by other components to identify this appender.
*
* @param string $name
*/
function setName($name)
{
// override me
}
/**
* Configurators call this method to determine if the appender
* requires a layout.
*
* <p>If this method returns <i>true</i>, meaning that layout is required,
* then the configurator will configure a layout using the configuration
* information at its disposal. If this method returns <i>false</i>,
* 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.</p>
*
* <p>In the rather exceptional case, where the appender
* implementation admits a layout but can also work without it, then
* the appender should return <i>true</i>.</p>
*
* @return boolean
*/
function requiresLayout()
{
// override me
}
}
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,80 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
require_once(LOG4PHP_DIR . '/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.
*
* <p>For file based configuration see {@link LoggerPropertyConfigurator}.
* <p>For XML based configuration see {@link LoggerDOMConfigurator}.
*
* @author VxR <[email protected]>
* @version $Revision: 1.2 $
* @package log4php
* @since 0.5
*/
class LoggerBasicConfigurator extends LoggerConfigurator {
function LoggerBasicConfigurator()
{
return;
}
/**
* Add a {@link LoggerAppenderConsole} that uses
* the {@link LoggerLayoutTTCC} to the root category.
*
* @param string $url not used here
* @static
*/
function configure($url = null)
{
$root =& LoggerManager::getRootLogger();
$appender =& LoggerAppender::singleton('A1', 'LoggerAppenderConsole');
$layout = LoggerLayout::factory('LoggerLayoutTTCC');
$appender->setLayout($layout);
$root->addAppender($appender);
}
/**
* Reset the default hierarchy to its defaut.
* It is equivalent to
* <code>
* LoggerManager::resetConfiguration();
* </code>
*
* @see LoggerHierarchy::resetConfiguration()
* @static
*/
function resetConfiguration()
{
LoggerManager::resetConfiguration();
}
}
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,52 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
require_once(LOG4PHP_DIR . '/spi/LoggerFactory.php');
require_once(LOG4PHP_DIR . '/Logger.php');
/**
* Creates instances of {@link Logger} with a given name.
*
* @author VxR <[email protected]>
* @version $Revision: 1.2 $
* @package log4php
* @since 0.5
*/
class LoggerDefaultCategoryFactory extends LoggerFactory {
function LoggerDefaultCategoryFactory()
{
return;
}
/**
* @param string $name
* @return Logger
*/
function makeNewLoggerInstance($name)
{
return new Logger($name);
}
}
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,98 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
* Extend this abstract class to create your own log layout format.
*
* @author VxR <[email protected]>
* @version $Revision: 1.10 $
* @package log4php
* @abstract
*/
class LoggerLayout {
/**
* Creates LoggerLayout instances with the given class name.
*
* @param string $class
* @return LoggerLayout
*/
function factory($class)
{
if (!empty($class)) {
$class = basename($class);
if (!class_exists($class))
@include_once(LOG4PHP_DIR . "/layouts/{$class}.php");
if (class_exists($class))
return new $class();
}
return null;
}
/**
* Override this method
*/
function activateOptions()
{
// override;
}
/**
* Override this method to create your own layout format.
*
* @param LoggerLoggingEvent
* @return string
*/
function format($event)
{
return $event->getRenderedMessage();
}
/**
* Returns the content type output by this layout.
* @return string
*/
function getContentType()
{
return "text/plain";
}
/**
* Returns the footer for the layout format.
* @return string
*/
function getFooter()
{
return null;
}
/**
* Returns the header for the layout format.
* @return string
*/
function getHeader()
{
return null;
}
}
?>
@@ -0,0 +1,264 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
*/
require_once(LOG4PHP_DIR . '/LoggerLog.php');
define('LOG4PHP_LEVEL_OFF_INT', 2147483647);
define('LOG4PHP_LEVEL_FATAL_INT', 50000);
define('LOG4PHP_LEVEL_ERROR_INT', 40000);
define('LOG4PHP_LEVEL_WARN_INT', 30000);
define('LOG4PHP_LEVEL_INFO_INT', 20000);
define('LOG4PHP_LEVEL_DEBUG_INT', 10000);
define('LOG4PHP_LEVEL_ALL_INT', -2147483648);
/**
* Defines the minimum set of levels recognized by the system, that is
* <i>OFF</i>, <i>FATAL</i>, <i>ERROR</i>,
* <i>WARN</i>, <i>INFO</i, <i>DEBUG</i> and
* <i>ALL</i>.
*
* <p>The <i>LoggerLevel</i> class may be subclassed to define a larger
* level set.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.11 $
* @package log4php
* @since 0.5
*/
class LoggerLevel {
/**
* @var integer
*/
var $level;
/**
* @var string
*/
var $levelStr;
/**
* @var integer
*/
var $syslogEquivalent;
/**
* Constructor
*
* @param integer $level
* @param string $levelStr
* @param integer $syslogEquivalent
*/
function LoggerLevel($level, $levelStr, $syslogEquivalent)
{
$this->level = $level;
$this->levelStr = $levelStr;
$this->syslogEquivalent = $syslogEquivalent;
}
/**
* Two priorities are equal if their level fields are equal.
*
* @param object $o
* @return boolean
*/
function equals($o)
{
if (is_a($o, 'loggerlevel')) {
return ($this->level == $o->level);
} else {
return false;
}
}
/**
* Returns an Off Level
* @static
* @return LoggerLevel
*/
function &getLevelOff()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_OFF_INT, 'OFF', 0);
return $level;
}
/**
* Returns a Fatal Level
* @static
* @return LoggerLevel
*/
function &getLevelFatal()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_FATAL_INT, 'FATAL', 0);
return $level;
}
/**
* Returns an Error Level
* @static
* @return LoggerLevel
*/
function &getLevelError()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ERROR_INT, 'ERROR', 3);
return $level;
}
/**
* Returns a Warn Level
* @static
* @return LoggerLevel
*/
function &getLevelWarn()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_WARN_INT, 'WARN', 4);
return $level;
}
/**
* Returns an Info Level
* @static
* @return LoggerLevel
*/
function &getLevelInfo()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_INFO_INT, 'INFO', 6);
return $level;
}
/**
* Returns a Debug Level
* @static
* @return LoggerLevel
*/
function &getLevelDebug()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_DEBUG_INT, 'DEBUG', 7);
return $level;
}
/**
* Returns an All Level
* @static
* @return LoggerLevel
*/
function &getLevelAll()
{
static $level;
if (!isset($level)) $level = new LoggerLevel(LOG4PHP_LEVEL_ALL_INT, 'ALL', 7);
return $level;
}
/**
* Return the syslog equivalent of this priority as an integer.
* @final
* @return integer
*/
function getSyslogEquivalent()
{
return $this->syslogEquivalent;
}
/**
* Returns <i>true</i> if this level has a higher or equal
* level than the level passed as argument, <i>false</i>
* otherwise.
*
* <p>You should think twice before overriding the default
* implementation of <i>isGreaterOrEqual</i> method.
*
* @param LoggerLevel $r
* @return boolean
*/
function isGreaterOrEqual($r)
{
return $this->level >= $r->level;
}
/**
* Returns the string representation of this priority.
* @return string
* @final
*/
function toString()
{
return $this->levelStr;
}
/**
* Returns the integer representation of this level.
* @return integer
*/
function toInt()
{
return $this->level;
}
/**
* Convert the string passed as argument to a level. If the
* conversion fails, then this method returns a DEBUG Level.
*
* @param mixed $arg
* @param LoggerLevel $default
* @static
*/
function &toLevel($arg, $defaultLevel = null)
{
if ($defaultLevel === null) {
return LoggerLevel::toLevel($arg, LoggerLevel::getLevelDebug());
} else {
if (is_int($arg)) {
switch($arg) {
case LOG4PHP_LEVEL_ALL_INT: return LoggerLevel::getLevelAll();
case LOG4PHP_LEVEL_DEBUG_INT: return LoggerLevel::getLevelDebug();
case LOG4PHP_LEVEL_INFO_INT: return LoggerLevel::getLevelInfo();
case LOG4PHP_LEVEL_WARN_INT: return LoggerLevel::getLevelWarn();
case LOG4PHP_LEVEL_ERROR_INT: return LoggerLevel::getLevelError();
case LOG4PHP_LEVEL_FATAL_INT: return LoggerLevel::getLevelFatal();
case LOG4PHP_LEVEL_OFF_INT: return LoggerLevel::getLevelOff();
default: return $defaultLevel;
}
} else {
switch(strtoupper($arg)) {
case 'ALL': return LoggerLevel::getLevelAll();
case 'DEBUG': return LoggerLevel::getLevelDebug();
case 'INFO': return LoggerLevel::getLevelInfo();
case 'WARN': return LoggerLevel::getLevelWarn();
case 'ERROR': return LoggerLevel::getLevelError();
case 'FATAL': return LoggerLevel::getLevelFatal();
case 'OFF': return LoggerLevel::getLevelOff();
default: return $defaultLevel;
}
}
}
}
}
?>
@@ -0,0 +1,99 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
* Helper class for internal logging
*
* <p>It uses php {@link PHP_MANUAL#trigger_error trigger_error()} function
* to output messages.</p>
* <p>You need to recode methods to output messages in a different way.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.9 $
* @package log4php
*/
class LoggerLog {
/**
* 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
*/
function log($message, $errLevel = E_USER_NOTICE)
{
if (LoggerLog::internalDebugging())
trigger_error($message, $errLevel);
}
function internalDebugging($value = null)
{
static $debug = false;
if (is_bool($value))
$debug = $value;
return $debug;
}
/**
* Report a debug message.
*
* @param string $message log message
* @static
* @since 0.3
*/
function debug($message)
{
LoggerLog::log($message, E_USER_NOTICE);
}
/**
* Report an error message.
*
* @param string $message log message
* @static
* @since 0.3
*/
function error($message)
{
trigger_error($message, E_USER_ERROR);
}
/**
* Report a warning message.
*
* @param string $message log message
* @static
* @since 0.3
*/
function warn($message)
{
trigger_error($message, E_USER_WARNING);
}
}
?>
@@ -0,0 +1,129 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
*/
require_once(LOG4PHP_DIR . '/LoggerLog.php');
define('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 <i>mapped diagnostic contexts</i>.
*
* A <i>Mapped Diagnostic Context</i>, 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.
*
* <p><b><i>The MDC is managed on a per thread basis</i></b>.
*
* @author VxR <[email protected]>
* @version $Revision: 1.4 $
* @since 0.3
* @package log4php
*/
class LoggerMDC {
/**
* Put a context value as identified with the key parameter into the current thread's
* context map.
*
* <p>If the current thread does not have a context map it is
* created as a side effect.</p>
*
* <p>Note that you cannot put more than {@link LOGGER_MDC_HT_SIZE} keys.</p>
*
* @param string $key the key
* @param string $value the value
* @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.
*
* <p>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.</p>
*
* <p>This method has no side effects.</p>
*
* @param string $key
* @return string
* @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
*/
function remove($key)
{
unset($GLOBALS['log4php.LoggerMDC.ht'][$key]);
}
}
?>
@@ -0,0 +1,262 @@
<?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
*/
/**
* 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');
/**
* Use the LoggerManager to get Logger instances.
*
* @author VxR <[email protected]>
* @version $Revision: 1.18 $
* @package log4php
* @see Logger
* @todo create a configurator selector
*/
class LoggerManager {
/**
* check if a given logger exists.
*
* @param string $name logger name
* @static
* @return boolean
*/
function exists($name)
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->exists($name);
}
/**
* Returns an array this whole Logger instances.
*
* @static
* @see Logger
* @return array
*/
function getCurrentLoggers()
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->getCurrentLoggers();
}
/**
* Returns the root logger.
*
* @static
* @return object
* @see LoggerRoot
*/
function &getRootLogger()
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->getRootLogger();
}
/**
* Returns the specified Logger.
*
* @param string $name logger name
* @param LoggerFactory $factory a {@link LoggerFactory} instance or null
* @static
* @return Logger
*/
function &getLogger($name, $factory = null)
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->getLogger($name, $factory);
}
/**
* Returns the LoggerHierarchy.
*
* @static
* @return LoggerHierarchy
*/
function &getLoggerRepository()
{
return LoggerHierarchy::singleton();
}
/**
* Destroy loggers object tree.
*
* @static
* @return boolean
*/
function resetConfiguration()
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->resetConfiguration();
}
/**
* Does nothing.
* @static
*/
function setRepositorySelector($selector, $guard)
{
return;
}
/**
* Safely close all appenders.
* @static
*/
function shutdown()
{
$repository =& LoggerManager::getLoggerRepository();
return $repository->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.
*
* <p>If it is not user defined, log4php tries to autoconfigure using (in order):</p>
*
* - the <code>$_ENV['log4php.defaultInitOverride']</code> variable.
* - the <code>$GLOBALS['log4php.defaultInitOverride']</code> global variable.
* - defaults to <i>false</i>
*
* @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.
*
* <p>This constant tells configurator classes where the configuration
* file is located.</p>
* <p>If not set by user, log4php tries to set it automatically using
* (in order):</p>
*
* - the <code>$_ENV['log4php.configuration']</code> 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.
*
* <p>This constant is set with the fullname (path included but non the
* .php extension) of the configurator class that init procedure will use.</p>
* <p>If not set by user, log4php tries to set it automatically.</p>
* <p>If {@link LOG4PHP_CONFIGURATION} has '.xml' extension set the
* constants to '{@link LOG4PHP_DIR}/xml/{@link LoggerDOMConfigurator}'.</p>
* <p>Otherwise set the constants to
* '{@link LOG4PHP_DIR}/{@link LoggerPropertyConfigurator}'.</p>
*
* <p><b>Security Note</b>: classfile pointed by this constant will be brutally
* included with a:
* <code>@include_once(LOG4PHP_CONFIGURATOR_CLASS . ".php");</code></p>
*
* @var string
*/
define('LOG4PHP_CONFIGURATOR_CLASS', LOG4PHP_DIR . '/LoggerPropertyConfigurator');
}
}
if (!LOG4PHP_DEFAULT_INIT_OVERRIDE) {
if (!LoggerManagerDefaultInit())
LoggerLog::warn("LOG4PHP main() Default Init failed.");
}
/**
* Default init procedure.
*
* <p>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.</p>
* <p>Users can skip this procedure using {@link LOG4PHP_DEFAULT_INIT_OVERRIDE}
* constant.</p>
*
* @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;
}
}
?>
@@ -0,0 +1,240 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
*/
require_once(LOG4PHP_DIR . '/LoggerLog.php');
define('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 <i>nested diagnostic contexts</i> as
* defined by Neil Harrison in the article "Patterns for Logging
* Diagnostic Messages" part of the book "<i>Pattern Languages of
* Program Design 3</i>" edited by Martin et al.
*
* <p>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.
*
* <p>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.
*
* <p><i><b>Note that NDCs are managed on a per thread
* basis</b></i>. NDC operations such as {@link push()}, {@link pop()},
* {@link clear()}, {@link getDepth()} and {@link setMaxDepth()}
* affect the NDC of the <i>current</i> thread only. NDCs of other
* threads remain unaffected.
*
* <p>For example, a servlet can build a per client request NDC
* consisting the clients host name and other information contained in
* the the request. <i>Cookies</i> are another source of distinctive
* information. To build an NDC one uses the {@link push()}
* operation.</p>
*
* Simply put,
*
* - Contexts can be nested.
* - When entering a context, call
* <code>LoggerNDC::push()</code>
* 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
* <code>LoggerNDC::pop()</code>
* - <b>When exiting a thread make sure to call {@link remove()}</b>
*
* <p>There is no penalty for forgetting to match each
* <code>push</code> operation with a corresponding <code>pop</code>,
* except the obvious mismatch between the real application context
* and the context set in the NDC.</p>
*
* <p>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.</p>
*
*
* @author VxR <[email protected]>
* @version $Revision: 1.5 $
* @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.
*
* <p>This method is equivalent to calling the {@link setMaxDepth()}
* method with a zero <var>maxDepth</var> 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.
*
* <p>The returned value is the value that was pushed last. If no
* context is available, then the empty string "" is returned.</p>
*
* @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.
*
* <p>The returned value is the value that was pushed last. If no
* context is available, then the empty string "" is returned.</p>
* @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.
*
* <p>The contents of the <var>message</var> 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 <var>maxDepth</var>, then no
* action is taken.
*
* <p>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;
}
}
}
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,101 @@
<?php
/**
* log4php is a PHP port of the log4j java logging package.
*
* <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
* <p>Design, strategies and part of the methods documentation are developed by log4j team
* (Ceki Gülcü as log4j project founder and
* {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
*
* <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
* For more information, please see {@link http://www.vxr.it/log4php/}.</p>
*
* <p>This software is published under the terms of the LGPL License
* a copy of which has been included with this distribution in the LICENSE file.</p>
*
* @package log4php
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
/**
*/
require_once(LOG4PHP_DIR . '/Logger.php');
require_once(LOG4PHP_DIR . '/LoggerLevel.php');
/**
* The root logger.
*
* @author VxR <[email protected]>
* @version $Revision: 1.9 $
* @package log4php
* @see Logger
*/
class LoggerRoot extends Logger {
/**
* @var string name of logger
*/
var $name = 'root';
/**
* @var object must be null for LoggerRoot
*/
var $parent = null;
/**
* Constructor
*
* @param integer $level initial log level
*/
function LoggerRoot($level = null)
{
$this->Logger($this->name);
if ($level == null)
$level = LoggerLevel::getLevelAll();
$this->setLevel($level);
}
/**
* @return integer the level
*/
function getChainedLevel()
{
return $this->level;
}
/**
* Setting a null value to the level of the root category may have catastrophic results.
* @param LoggerLevel $level
*/
function setLevel($level)
{
$this->level = $level;
}
/**
* Please use setLevel() instead.
* @param LoggerLevel $level
* @deprecated
*/
function setPriority($level)
{
$this->setLevel($level);
}
/**
* Always returns false.
* Because LoggerRoot has no parents, it returns false.
* @param Logger $parent
* @return boolean
*/
function setParent($parent)
{
return false;
}
}
?>
@@ -0,0 +1,139 @@
<?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 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.
*
* <p>Optional parameter is {@link $target}. The default target is Stdout.</p>
* <p><b>Note</b>: Use this Appender with command-line php scripts.
* On web scripts this appender has no effects.</p>
* <p>This appender requires a layout.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.11 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderConsole extends LoggerAppenderSkeleton {
/**
* Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive).
* Default is STDOUT
* @var string
*/
var $target = 'php://stdout';
/**
* @var boolean
* @access private
*/
var $requiresLayout = true;
/**
* @var mixed the resource used to open stdout/stderr
* @access private
*/
var $fp = false;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderConsole($name)
{
$this->LoggerAppenderSkeleton($name);
}
/**
* Set console target.
* @param mixed $value a constant or a string
*/
function setTarget($value)
{
$v = trim($value);
if ($v == LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT or strtoupper($v) == 'STDOUT') {
$this->target = LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT;
} elseif ($v == LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT or strtoupper($v) == 'STDERR') {
$target = LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT;
} else {
LoggerLog::debug(
"LoggerAppenderConsole::targetWarn() ".
"Invalid target. Using '".LOG4PHP_LOGGER_APPENDER_CONSOLE_STDOUT."' by default."
);
}
}
function getTarget()
{
return $this->target;
}
function activateOptions()
{
LoggerLog::debug("LoggerAppenderConsole::activateOptions()");
$this->fp = @fopen($this->getTarget(), 'w');
if ($this->fp and $this->layout !== null)
@fwrite($this->fp, $this->layout->getHeader());
$this->closed = (bool)($this->fp === false);
}
/**
* @see LoggerAppender::close()
*/
function close()
{
LoggerLog::debug("LoggerAppenderConsole::close()");
if ($this->fp and $this->layout !== null) {
@fwrite($this->fp, $this->layout->getFooter());
}
@fclose($this->fp);
$this->closed = true;
}
function append($event)
{
if ($this->fp and $this->layout !== null) {
LoggerLog::debug("LoggerAppenderConsole::append()");
@fwrite($this->fp, $this->layout->format($event));
}
}
}
?>
@@ -0,0 +1,97 @@
<?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 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.
* <p>Parameters are {@link $datePattern}, {@link $file}. Note that file
* parameter should include a '%s' identifier and should always be set
* before {@link $file} param.</p>
*
* @author Abel Gonzalez <[email protected]>
* @version $Revision: 1.7 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderDailyFile extends LoggerAppenderFile {
/**
* Format date.
* It follows the {@link PHP_MANUAL#date()} formatting rules and <b>should always be set before {@link $file} param</b>.
* @var string
*/
var $datePattern = "Ymd";
/**
* Constructor
*
* @param string $name appender name
*/
function LoggerAppenderDailyFile($name)
{
$this->LoggerAppenderFile($name);
}
/**
* Sets date format for the file name.
* @param string $format a regular date() string format
*/
function setDatePattern ( $format )
{
$this->datePattern = $format;
}
/**
* @return string returns date format for the filename
*/
function getDatePattern ( )
{
return $this->datePattern;
}
/**
* The File property takes a string value which should be the name of the file to append to.
* Sets and opens the file where the log output will go.
*
* @see LoggerAppenderFile::setFile()
*/
function setFile()
{
$numargs = func_num_args();
$args = func_get_args();
if ($numargs == 1 and is_string($args[0])) {
parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())) );
} elseif ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) {
parent::setFile( sprintf((string)$args[0], date($this->getDatePattern())), $args[1] );
}
}
}
?>
@@ -0,0 +1,209 @@
<?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 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.
*
* <p>This appender uses a table in a database to log events.</p>
* <p>Parameters are {@link $dsn}, {@link $createTable}, {@link table} and {@link $sql}.</p>
* <p>See examples in test directory.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.7 $
* @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->canAppend = false;
return;
}
}
$this->canAppend = true;
}
}
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;
}
}
?>
@@ -0,0 +1,89 @@
<?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 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.
*
* <p>This appender requires a layout.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.5 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderEcho extends LoggerAppenderSkeleton {
/**
* @access private
*/
var $requiresLayout = true;
/**
* @var boolean used internally to mark first append
* @access private
*/
var $firstAppend = true;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderEcho($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
return;
}
function close()
{
if (!$this->firstAppend)
echo $this->layout->getFooter();
$this->closed = true;
}
function append($event)
{
LoggerLog::debug("LoggerAppenderEcho::append()");
if ($this->layout !== null) {
if ($this->firstAppend) {
echo $this->layout->getHeader();
$this->firstAppend = false;
}
echo $this->layout->format($event);
}
}
}
?>
@@ -0,0 +1,184 @@
<?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 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 <b>file</b>),
* {@link $append}.
*
* @author VxR <[email protected]>
* @version $Revision: 1.15 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderFile extends LoggerAppenderSkeleton {
/**
* @var boolean if {@link $file} exists, appends events.
*/
var $append = true;
/**
* @var string the file name used to append events
*/
var $fileName;
/**
* @var mixed file resource
* @access private
*/
var $fp = false;
/**
* @access private
*/
var $requiresLayout = true;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderFile($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
$fileName = $this->getFile();
LoggerLog::debug("LoggerAppenderFile::activateOptions() opening file '{$fileName}'");
$this->fp = @fopen($fileName, ($this->getAppend()? 'a':'w'));
// Denying read option for log file. Added for Vulnerability fix
if (is_readable($fileName)) chmod ($fileName,0222);
if ($this->fp) {
if ($this->getAppend())
fseek($this->fp, 0, SEEK_END);
@fwrite($this->fp, $this->layout->getHeader());
$this->closed = false;
} else {
$this->closed = true;
}
}
function close()
{
if ($this->fp and $this->layout !== null)
@fwrite($this->fp, $this->layout->getFooter());
$this->closeFile();
$this->closed = true;
}
/**
* Closes the previously opened file.
*/
function closeFile()
{
if ($this->fp)
@fclose($this->fp);
}
/**
* @return boolean
*/
function getAppend()
{
return $this->append;
}
/**
* @return string
*/
function getFile()
{
return $this->getFileName();
}
/**
* @return string
*/
function getFileName()
{
return $this->fileName;
}
/**
* Close any previously opened file and call the parent's reset.
*/
function reset()
{
$this->closeFile();
$this->fileName = null;
parent::reset();
}
function setAppend($flag)
{
$this->append = LoggerOptionConverter::toBoolean($flag, true);
}
/**
* Sets and opens the file where the log output will go.
*
* This is an overloaded method. It can be called with:
* - setFile(string $fileName) to set filename.
* - setFile(string $fileName, boolean $append) to set filename and append.
*/
function setFile()
{
$numargs = func_num_args();
$args = func_get_args();
if ($numargs == 1 and is_string($args[0])) {
$this->setFileName($args[0]);
} elseif ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) {
$this->setFile($args[0]);
$this->setAppend($args[1]);
}
}
function setFileName($fileName)
{
$this->fileName = $fileName;
}
function append($event)
{
if ($this->fp and $this->layout !== null) {
LoggerLog::debug("LoggerAppenderFile::append()");
@fwrite($this->fp, $this->layout->format($event));
}
}
}
?>
@@ -0,0 +1,148 @@
<?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 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}.
*
* <p>Parameters are {@link $from}, {@link $to}, {@link $subject}.</p>
* <p>This appender requires a layout.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.8 $
* @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 = '';
/**
* @access private
*/
var $requiresLayout = true;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderMail($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
$this->closed = false;
return;
}
function close()
{
$from = $this->getFrom();
$to = $this->getTo();
if (!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) {
$subject = $this->getSubject();
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);
}
}
?>
@@ -0,0 +1,170 @@
<?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 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.
*
* <p>Parameters are
* {@link $smtpHost} (optional),
* {@link $port} (optional),
* {@link $from} (optional),
* {@link $to},
* {@link $subject} (optional).</p>
* <p>A layout is required.</p>
*
* @author Domenico Lordi <[email protected]>
* @author VxR <[email protected]>
* @version $Revision: 1.10 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderMailEvent extends LoggerAppenderSkeleton {
/**
* @var string 'from' field
*/
var $from = null;
/**
* @var integer 'from' field
*/
var $port = 25;
/**
* @var string hostname.
*/
var $smtpHost = null;
/**
* @var string 'subject' field
*/
var $subject = '';
/**
* @var string 'to' field
*/
var $to = null;
/**
* @access private
*/
var $requiresLayout = true;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderMailEvent($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
$this->closed = false;
}
function close()
{
$this->closed = true;
}
/**
* @return string
*/
function getFrom() { return $this->from; }
/**
* @return integer
*/
function getPort() { return $this->port; }
/**
* @return string
*/
function getSmtpHost() { return $this->smtpHost; }
/**
* @return string
*/
function getSubject() { return $this->subject; }
/**
* @return string
*/
function getTo() { return $this->to; }
function setFrom($from) { $this->from = $from; }
function setPort($port) { $this->port = (int)$port; }
function setSmtpHost($smtphost) { $this->smtpHost = $smtpHost; }
function setSubject($subject) { $this->subject = $subject; }
function setTo($to) { $this->to = $to; }
function append($event)
{
$from = $this->getFrom();
$to = $this->getTo();
if (empty($from) or empty($to))
return;
$smtpHost = $this->getSmtpHost();
$prevSmtpHost = ini_get('SMTP');
if (!empty($smtpHost)) {
ini_set('SMTP', $smtpHost);
} else {
$smtpHost = $prevSmtpHost;
}
$smtpPort = $this->getPort();
$prevSmtpPort= ini_get('smtp_port');
if ($smtpPort > 0 and $smtpPort < 65535) {
ini_set('smtp_port', $smtpPort);
} else {
$smtpPort = $prevSmtpPort;
}
LoggerLog::debug(
"LoggerAppenderMailEvent::append()" .
":from=[{$from}]:to=[{$to}]:smtpHost=[{$smtpHost}]:smtpPort=[{$smtpPort}]"
);
if (!@mail( $to, $this->getSubject(),
$this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event),
"From: {$from}\r\n"
)) {
LoggerLog::debug("LoggerAppenderMailEvent::append() mail error");
}
ini_set('SMTP', $prevSmtpHost);
ini_set('smtp_port', $prevSmtpPort);
}
}
?>
@@ -0,0 +1,72 @@
<?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 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 VxR <[email protected]>
* @version $Revision: 1.4 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderNull extends LoggerAppenderSkeleton {
/**
* @access private
*/
var $requiresLayout = false;
/**
* Constructor.
*
* @param string $name appender name
*/
function LoggerAppenderNull($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
$this->closed = false;
}
function close()
{
$this->closed = true;
}
/**
* Do nothing. How I Love it !! :)
*/
function append($event)
{
LoggerLog::debug("LoggerAppenderNull::append()");
}
}
?>
@@ -0,0 +1,85 @@
<?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 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.
*
* <p>Levels are mapped as follows:</p>
* - <b>level &lt; WARN</b> mapped to E_USER_NOTICE
* - <b>WARN &lt;= level &lt; ERROR</b> mapped to E_USER_WARNING
* - <b>level &gt;= ERROR</b> mapped to E_USER_ERROR
*
* @author VxR <[email protected]>
* @version $Revision: 1.11 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderPhp extends LoggerAppenderSkeleton {
/**
* @access private
*/
var $requiresLayout = false;
/**
* Constructor
*
* @param string $name appender name
*/
function LoggerAppenderPhp($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
$this->layout = LoggerLayout::factory('LoggerLayoutTTCC');
$this->closed = false;
}
function close()
{
$this->closed = true;
}
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);
}
}
}
}
?>
@@ -0,0 +1,241 @@
<?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 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.
*
* <p>Parameters are {@link $maxFileSize}, {@link $maxBackupIndex}.</p>
*
* <p>Contributors: Sergio Strampelli.</p>
*
* @author VxR <[email protected]>
* @version $Revision: 1.14 $
* @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.
*
* <p>In configuration files, the <var>MaxFileSize</var> 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.</p>
* <p>The default maximum file size is 10MB.</p>
*
* <p>Note that MaxFileSize cannot exceed <b>2 GB</b>.</p>
*
* @var integer
*/
var $maxFileSize = 10485760;
/**
* Set the maximum number of backup files to keep around.
*
* <p>The <var>MaxBackupIndex</var> 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.</p>
* <p>There is one backup file by default.</p>
*
* @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.
*
* <p>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.
*
* <p>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;
//As of now suppress the error in rename. we have to handle in future
@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.
*
* <p>The <b>MaxBackupIndex</b> 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.
* <p>In configuration files, the <b>MaxFileSize</b> 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();
}
}
}
?>
@@ -0,0 +1,285 @@
<?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 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 VxR <[email protected]>
* @version $Revision: 1.17 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderSocket extends LoggerAppenderSkeleton {
/**
* @var mixed socket connection resource
* @access private
*/
var $sp = false;
/**
* Target host. On how to define remote hostaname see
* {@link PHP_MANUAL#fsockopen}
* @var string
*/
var $remoteHost = '';
/**
* @var integer the network port.
*/
var $port = LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_PORT;
/**
* @var boolean get event's location info.
*/
var $locationInfo = false;
/**
* @var integer connection timeout
*/
var $timeout = LOG4PHP_LOGGER_APPENDER_SOCKET_DEFAULT_TIMEOUT;
/**
* @var boolean output events via {@link LoggerXmlLayout}
*/
var $useXml = false;
/**
* @var boolean forward this option to {@link LoggerXmlLayout}.
* Ignored if {@link $useXml} is <i>false</i>.
*/
var $log4jNamespace = false;
/**
* @var LoggerXmlLayout
* @access private
*/
var $xmlLayout = null;
/**
* @var boolean
* @access private
*/
var $requiresLayout = false;
/**
* Constructor
*
* @param string $name appender name
*/
function LoggerAppenderSocket($name)
{
$this->LoggerAppenderSkeleton($name);
}
/**
* Create a socket connection using defined parameters
*/
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;
}
}
function close()
{
@fclose($this->sp);
$this->closed = true;
}
/**
* @return string
*/
function getHostname()
{
return $this->getRemoteHost();
}
/**
* @return boolean
*/
function getLocationInfo()
{
return $this->locationInfo;
}
/**
* @return boolean
*/
function getLog4jNamespace()
{
return $this->log4jNamespace;
}
/**
* @return integer
*/
function getPort()
{
return $this->port;
}
function getRemoteHost()
{
return $this->remoteHost;
}
/**
* @return integer
*/
function getTimeout()
{
return $this->timeout;
}
/**
* @var boolean
*/
function getUseXml()
{
return $this->useXml;
}
function reset()
{
$this->close();
parent::reset();
}
/**
* @param string
* @deprecated Please, use {@link setRemoteHost}
*/
function setHostname($hostname)
{
$this->setRemoteHost($hostname);
}
/**
* @param mixed
*/
function setLocationInfo($flag)
{
$this->locationInfo = LoggerOptionConverter::toBoolean($flag, $this->getLocationInfo());
}
/**
* @param mixed
*/
function setLog4jNamespace($flag)
{
$this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, $this->getLog4jNamespace());
}
/**
* @param integer
*/
function setPort($port)
{
$port = LoggerOptionConverter::toInt($port, 0);
if ($port > 0 and $port < 65535)
$this->port = $port;
}
/**
* @param string
*/
function setRemoteHost($hostname)
{
$this->remoteHost = $hostname;
}
/**
* @param integer
*/
function setTimeout($timeout)
{
$this->timeout = LoggerOptionConverter::toInt($timeout, $this->getTimeout());
}
/**
* @param mixed
*/
function setUseXml($flag)
{
$this->useXml = LoggerOptionConverter::toBoolean($flag, $this->getUseXml());
}
/**
* @param LoggerLoggingEvent
*/
function append($event)
{
if ($this->sp) {
LoggerLog::debug("LoggerAppenderSocket::append()");
if ($this->getLocationInfo())
$event->getLocationInfo();
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);
}
}
}
?>
@@ -0,0 +1,85 @@
<?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 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:
* - <b>level &gt;= FATAL</b> to LOG_ALERT
* - <b>FATAL &gt; level &gt;= ERROR</b> to LOG_ERR
* - <b>ERROR &gt; level &gt;= WARN</b> to LOG_WARNING
* - <b>WARN &gt; level &gt;= INFO</b> to LOG_INFO
* - <b>INFO &gt; level &gt;= DEBUG</b> to LOG_DEBUG
*
* @author VxR <[email protected]>
* @version $Revision: 1.11 $
* @package log4php
* @subpackage appenders
*/
class LoggerAppenderSyslog extends LoggerAppenderSkeleton {
/**
* Constructor
*
* @param string $name appender name
*/
function LoggerAppenderSyslog($name)
{
$this->LoggerAppenderSkeleton($name);
}
function activateOptions()
{
define_syslog_variables();
$this->closed = false;
}
function close()
{
closelog();
$this->closed = true;
}
function append($event)
{
$level = $event->getLevel();
$message = $event->getRenderedMessage();
if ($level->isGreaterOrEqual(LoggerLevel::getLevelFatal())) {
syslog(LOG_ALERT, $message);
} elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
syslog(LOG_ERR, $message);
} elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
syslog(LOG_WARNING, $message);
} elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelInfo())) {
syslog(LOG_INFO, $message);
} elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelDebug())) {
syslog(LOG_DEBUG, $message);
}
}
}
?>
@@ -0,0 +1,37 @@
<?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 config
*/
/**
* @ignore
*/
if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
/**
* @author VxR <[email protected]>
* @version $Revision: 1.2 $
* @package log4php
* @subpackage config
* @since 0.5
* @todo Ehm... try to guess...
*/
class LoggerPropertyGetter {
}
?>
@@ -0,0 +1,161 @@
<?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 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:
* <code>
* $ps = new LoggerPropertySetter($anObject);
* $ps->set("name", "Joe");
* $ps->set("age", 32);
* $ps->set("isMale", true);
* </code>
* will cause the invocations
* <code>
* $anObject->setName("Joe");
* $anObject->setAge(32);
* $anObject->setMale(true)
* </code>
* if such methods exist.
*
* @author VxR <[email protected]>
* @version $Revision: 1.4 $
* @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 <code>properties</code> are parsed relative to a
* <code>prefix</code>.
*
* @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
* <code>prefix</code> 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.
*
* <p>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.");
}
}
}
?>
@@ -0,0 +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 <[email protected]>
* @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}");
}
}
?>

Some files were not shown because too many files have changed in this diff Show More