I'm trying to use log4php to create logs whenever a function is successful/unsuccessful on my website,but it seems the most basic of code isn't working for me. I've included all my code below. Would appreciate if anyone can spot my careless mistake or if I'm doing it completely wrong and give some advice?
I have the log4php downloaded and have placed the contents of the php directory in my web application folder in a folder named "log4php"
config.xml which is in the root of my web application folder
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="myConsoleAppender" class="LoggerAppenderConsole" />
<appender name="errorDef" class="LoggerAppenderDailyFile" threshold="error">
<param name="append" value="true"/>
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{Y-m-d H:i:s,u} [%logger] %message%newline" />
</layout>
<param name="file" value="logs/log-error-%s.log" />
<param name="datePattern" value="Y-m-d.H" />
</appender>
<appender name="debugDef" class="LoggerAppenderDailyFile" threshold="debug">
<param name="append" value="true"/>
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{Y-m-d H:i:s,u} [%logger] %message%newline" />
</layout>
<param name="file" value="logs/logs-%s.log" />
<param name="datePattern" value="Y-m-d.H" />
</appender>
<root>
<appender_ref ref="errorDef" />
<appender_ref ref="debugDef" />
</root>
*Note, I do have a folder named log in the web application folder to store to logs
LoggerConfig.php which is in the log4php folder.
<?php
include 'log4php/Logger.php';
Logger::configure('config.xml');
?>
checkLogin.php which is the thing I would like to have logged.
<?php
include 'log4php/LoggerConfig.php';
$logger=Logger::getLogger("Login");
//the standard sql login procedure
if($userfound >= 1)
{
//standard procedure to fetch assoc etc
$logger->debug("Login Successful") or die ("Login Successful but did not log");
//header to index commented as I want to see the or die if it does happen
}
else
{
$logger->error("Login Failed") or die("Login Failed but did no log");
//header back to login page but commented as I want to see the or die if it does happen
}
Besides the part where I use the threshold debug and error, have I misunderstood the configuration documentation? Please advice! Thanks in advance.