Question

In log4php configuration documentation, there is a configuration option called "additivity" which stops the inheritance from root loggers.

However, I added to the PHP-format configuration file, root logger is still logging the entry that supposed to appear inside logger queryLogger only:

<?php
return array(
    'rootLogger' => array(
        'level' => 'DEBUG',
        'appenders' => array('fileAppender'),
    ),
    'loggers' => array(
        'queryLogger' => array(
            'level' => 'INFO',
            'appenders' => array('queryFileAppender')
        )
    ),
    'appenders' => array(
        'fileAppender' => array(
            'class' => 'LoggerAppenderDailyFile',
            'layout' => array(
                'class' => 'LoggerLayoutPattern',
                'params' => array(
                    'conversionPattern' => '%d{Y-m-d H:i:s.u} [%-5p] %-100m ---------- [%F:%L]%n'
                )
            ),
            'params' => array(
                'datePattern' => 'Y-m-d',
                'file' => LOG_PATH . 'system-%s.log',
            ),
        ),
        'queryFileAppender' => array(
            'class' => 'LoggerAppenderDailyFile',
            'layout' => array(
                'class' => 'LoggerLayoutPattern',
                'params' => array(
                    'conversionPattern' => '%d{Y-m-d H:i:s.u} %m%n'
                )
            ),
            'params' => array(
                'datePattern' => 'Y-m-d',
                'file' => LOG_PATH . 'query-%s.log',
            ),
        ),
    ),
    'additivity' => array(
        'fileAppender' => false,
    ),
);
?>

My goal is to only log in queryLogger, but not in rootLogger. What did I miss?

Was it helpful?

Solution

This is probably badly documented, because there is no real example of how to configure additivity beside the outdated example of the INI way (which is deprecated).

But looking at the XML example of https://logging.apache.org/log4php/docs/loggers.html (Subchapter "Disabling appender additivity") reveals that additivity is a setting of the logger itself - it does not stand on it's own (the INI way of configuring things makes you think so).

And by looking at the code in LoggerConfiguratorDefault::configureLogger it becomes clear that additivity is a subkey parallel to level and appenders in the individual logger configuration.

So this should work:

// ...
'loggers' => array(
    'queryLogger' => array(
        'level' => 'INFO',
        'appenders' => array('queryFileAppender'),
        'additivity' => false
    )
),    //...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top