Apache Log4php Usage Example">

<?php 
/**
 * This is a log4php usage example file
 *
 */

/**
 * Set LOG4PHP_DIR to Your log4php root dir or it will
 * be set automatically at the first require_once().
 * Here 'log4php' is an 'include_path' subdir.
 */
define('LOG4PHP_DIR', 'log4php');

/*
    1.  If you want to use a custom Configurator,
        set the LOG4PHP_CONFIGURATOR_CLASS constants to Your Configurator class file.
        The class name must have the same base name of the classfile.

         Ex: define('LOG4PHP_CONFIGURATOR_CLASS', '/my/path/LoggerMyConfigurator');

          Log4php will try to include '/my/path/LoggerMyConfigurator.php'
          and instantiate a 'LoggerMyConfigurator' class.

    2.  If you want to use a configuration file that's not the default,
        set the LOG4PHP_CONFIGURATION constants to Your configuration filename.

        Ex: define('LOG4PHP_CONFIGURATION', '/my/path/my_config.conf');

        Note that if config extension is NOT .xml and LOG4PHP_CONFIGURATOR_CLASS
        is not defined, the LoggerPropertyConfigurator will be used.

    3.  If you want to bypass the initial configuration procedure, set the 
        'LOG4PHP_DEFAULT_INIT_OVERRIDE' to true.

         Ex: define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true);
*/

require_once(LOG4PHP_DIR. '/LoggerManager.php');
/* 
    Or You can use:

    require_once('/my/log4php/path/LoggerManager.php');

    and LOG4PHP_DIR will be automatically set to '/my/log4php/path'.
*/

class Test {

    var $logger;

    function Test()
    {
        $this->logger =& LoggerManager::getLogger('Test');
    }

    function testLog()
    {
        $this->logger->debug('this is a DEBUG log generated by Test::testLog() class');
        $this->logger->info('this is an INFO log generated by Test::testLog() class');
        $this->logger->warn('this is a WARN log generated by Test::testLog() class');
        $this->logger->error('this is an ERROR log generated by Test::testLog() class');
        $this->logger->fatal('this is a FATAL log generated by Test::testLog() class');
     }
}

class TestTest extends Test {
    var $logger;

    function TestTest()
    {
        $this->Test();
        $this->logger =& LoggerManager::getLogger('Test.Test');
    }

    function testLog()
    {
        LoggerNDC::push('NDC generated by TestTest::testLog()');

        $this->logger->debug('this is a DEBUG log generated by TestTest::testLog() class');
        $this->logger->info('this is an INFO log generated by TestTest::testLog() class');
        $this->logger->warn('this is a WARN log generated by TestTest::testLog() class');
        $this>->logger->error('this is an ERROR log generated by TestTest::testLog() class');
        $this->logger->fatal('this is a FATAL log generated by TestTest::testLog() class');

        LoggerNDC::pop();
    }
} 

function Bar()
{
    $logger =& LoggerManager::getLogger('bar');

    /* 
    note that the message here is an array
    */ 
    
    $logger->debug(array('one', 'two', 'tree'));
    $logger->info('this is an INFO log generated by Bar() function');
    $logger->warn('this is a WARN log generated by Bar() function');
    $logger->error('this is an ERROR log generated by Bar() function');
    $logger->fatal('this is a FATAL log generated by Bar() function');
}

$logger =& LoggerManager::getLogger('main');
$logger->debug('this is a DEBUG log generated by main() function');
$logger->info('this is an INFO log generated by main() function');
$logger->warn('this is a WARN log generated by main() function');
$logger->error('this is an ERROR log generated by main() function');
$logger->fatal('this is a FATAL log generated by main() function')

$test = new Test();
$test->testLog();

$testTest = new TestTest();
$testTest->testLog();

Bar();
?>