I am using log4j to manage logs in my java application.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{1}:%L %m %n" />
</layout>
</appender>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="INFO" />
<param name="Threshold" value="DEBUG" />
<param name="maxFileSize" value="10MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="C:/test_reports/infoToolsLog.log"/>
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L %m %n" />
</layout>
</appender>
<root>
<level value="info" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
Test Code:
import org.apache.log4j.Logger;
public class TestLogFile {
private static final Logger LOGGER = Logger.getLogger(TestLogFile.class);
public static void main(String args[]){
System.out.println("In TestLogFIle");
LOGGER.info("in TestLogFile, info statement");
LOGGER.debug("in TestLogFile debug statement");
LOGGER.error("in TestLogfile, error statement");
int i=10;
try {
int j=i/0;
}catch(Exception e){
LOGGER.error("error occured in TestLogfile : " ,e);
}
}
}
messages displayed in log file :
2017-06-16 11:34:57 INFO TestLogFile:10 in TestLogFile, info statement
2017-06-16 11:34:57 ERROR TestLogFile:12 in TestLogfile, error statement
2017-06-16 11:34:57 ERROR TestLogFile:18 error occured in TestLogfile :
java.lang.ArithmeticException: / by zero...
When <level value="info" />
, how to show the debug statements also included in log file.
What changes need to be done to to show info,error and debug statements printed in the log file when <level value="info" />