phplog4php

log4php : Cannot create log file


I use log4php to write file logs. Here is the configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="default" class="LoggerAppenderDailyFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%date %logger %-5level %msg%n" />
        </layout>
        <param name="file" value="/path/to/log/register-%s.log" />
        <param name="datePattern" value="Y-m-d" />
        <param name="append" value="true" />
    </appender>
    <root>
        <level value="info" />
        <appender_ref ref="default" />
    </root>
</configuration>

And here is the initialization codes in PHP :

require_once('/path/to/log4php/Logger.php');
require_once('/path/to/log4php.xml');
$logger = Logger::getLogger(basename(__FILE__));
$logger->info('Testing');

the folder permission is set to 777 ( it's a Ubuntu Linux server ), but the log file didn't create. How do I debug the log4php?


Solution

  • Proper way of calling with config would be:

    require_once('/path/to/log4php/Logger.php');
    Logger::configure('/path/to/log4php.xml');
    $logger = Logger::getLogger(basename(__FILE__));
    $logger->info('Testing');
    

    As Shivan Raptor stated, first thing to do is to check logs for permission problems.