0

I'd like to create multiple loggers where different areas of my app will log to different files. For example, all the classes associated with getting the users data would log to a user.log, all functionality of making purchases going to a purchase.log. I am using the configuration array method for setting up the logger & appenders. In my index.php:

require_once('log4php/Logger.php');
require_once('classB.php');
require_once('classA.php');

 Logger::configure(array(
'rootLogger' => array('appenders' => array('default')),
'classALogger' => array('appenders' => array('classAAppender')),
'appenders' => array(
    'default' => array(
        'class' => 'LoggerAppenderEcho',
        'layout' => array(
            'class' => 'LoggerLayoutSimple'
            )
    ),'classAAppender' => array(
        'class' => 'LoggerAppenderFile',
        'additivity' => false,
        'layout' => array(
            'class' => 'LoggerLayoutSimple'
        ),
        'params' => array(
            'file' => 'log/classA.log',
            'append' => true
        )
    )
),

));

$logger = Logger::getLogger("main");
$logger->info('message from index' . '<br>');

$classA = new ClassA();
$classA->test();

Class A is as follows:

class ClassA
{   
    public function test()
    {
        $logger = Logger::getLogger("classALogger");

        $logger->error('from ClassA');
    }
}

I am able to log to the default or root logger but am not able to log to, in this example, classALogger. Any suggestions?

mudface
  • 93
  • 1
  • 6
  • You might try assigning that array of arrays to a var and then doing a vardump on it - just to make sure it's setup like you think it is. – ethrbunny Dec 30 '13 at 21:03
  • Yes, it was setup like I thought it was after dumping the array. – mudface Dec 30 '13 at 21:53

0 Answers0