i have a problem configuring log4php and i don't know where to check on the documentation. I have this config:
Logger::configure(array(
'rootLogger' => array(
'level' => 'INFO',
'appenders' => array('info'),
),
'loggers' => array(
'debug' => array(
'level' => 'DEBUG',
'appenders' => array('debug'),
'additivity' => false
),
'error' => array(
'level' => 'ERROR',
'appenders' => array('error'),
'additivity' => false
)
),
'appenders' => array(
'info' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-info-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'info',
'levelMax' => 'info',
)
)
),
'debug' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-debug-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'debug',
'levelMax' => 'debug',
)
)
),
'error' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-error-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'error',
'levelMax' => 'error',
)
)
)
)
));
Usage: I define once the
$logger = Logger::getLogger(basename(__FILE__));
and then i log what i need like so:
$logger->info("INFO");
$logger->debug("DEBUG");
$logger->error("ERROR");
but only info's log file is created. I used the PHP way to configure the logger because for me it seems to be the easiest way to do it, but there isn't a lot of documentations about this way of doing the conf. What am i doing wrong?
well, it took me awhile to get it to work too. my current config works:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="default" class="LoggerAppenderRollingFile" threshold="DEBUG">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date %-30logger %-5level %msg%n"/>
</layout>
<param name="file" value="/mnt/media/log/backend.debug.log"/>
<param name="maxFileSize" value="100MB"/>
<param name="maxBackupIndex" value="20"/>
</appender>
<appender name="splunk" class="LoggerAppenderRollingFile" threshold="INFO">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date %-30logger %-5level %msg%n"/>
</layout>
<param name="file" value="/mnt/media/log/backend.log"/>
<param name="maxFileSize" value="100MB"/>
<param name="maxBackupIndex" value="20"/>
</appender>
<appender name="console" class="LoggerAppenderConsole" threshold="DEBUG">
<layout class="LoggerLayoutSimple">
</layout>
</appender>
<root>
<level value="TRACE"/>
<appender_ref ref="default"/>
<appender_ref ref="splunk"/>
<appender_ref ref="console"/>
</root>
To use this
$configurator = new LoggerConfiguratorDefault();
$logConfig = $configurator->parse(__DIR__ . "/config/log4php_backend.xml"); // this is where my xml file is located
Logger::configure($logConfig);
This is the version i compose into the app
"apache/log4php" : "^2.3"