After unpacking the distribution file the following source tree will be created:
log4php-{version}
+---docs
| +---api
| qsg.html (this file)
| ...
\---src
+---log4php
| +---appenders
| +---config
| +---helpers
| +---layouts
| +---or
| +---spi
| +---varia
| \---xml
\---tests
...
Copy the "log4php-{version}/src/log4php" directory in a place accessible by PHP
(called in this document {LOG4PHP-ROOT})
and that's all! Log4php is installed.
Optionally the LOG4PHP_DIR
constant can be defined to point to {LOG4PHP-ROOT}.
Three steps are required to use log4php:
tests/*/configs directories for examples.log4php.dtd for xml elements reference.LOG4PHP_CONFIGURATION
constant to point to the configuration above.
LOG4PHP_CONFIGURATOR_CLASS
constant to point to a configuration class file.
LoggerManager.php'
class file in your php scripts.
Once the 'LoggerManager' is included,
it will start the default init procedure
that can be parameterized by the previously defined
LOG4PHP_DEFAULT_INIT_OVERRIDE,
LOG4PHP_CONFIGURATION and
LOG4PHP_CONFIGURATOR_CLASS
constants.
Here is how to use log4php in user PHP code:
<?php
// Setting default timezone
date_default_timezone_set('Europe/London');
/*
Set LOG4PHP_* constants here
*/
require_once(LOG4PHP_DIR . '/LoggerManager.php');
/*
In a class
*/
class Log4phpTest {
/*
Your public and private vars
*/
var $_logger;
function Log4phpTest()
{
$this->_logger =& LoggerManager::getLogger('Log4phpTest');
$this->_logger->debug('Hello!');
}
}
function Log4phpTestFunction()
{
$logger =& LoggerManager::getLogger('Log4phpTestFunction');
$logger->debug('Hello again!');
}
/*
Your PHP code
*/
//Safely close all appenders with...
LoggerManager::shutdown();
?>