I am using SLF4J and as per requirement i have to store the logs into the .log file. But when i run the program the log are not written into thelog file.
Class :
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestSLF4J {
// private static Logger _logger = LoggerFactory.getLogger(TestSLF4J.class);
private static Logger _logger = LoggerFactory.getLogger(TestSLF4J.class);
public static void main(String[] args) {
logger .debug("Sample debug message");
logger .info("Sample info message");
logger .warn("Sample warn message");
logger .error("Sample error message");
}
}
log4j.properties
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=C:/checkLog.log
log4j.appender.file.threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=DEBUG,file
i can see info,warn,error on console but not debug value..!!
Can anyone help me store log into the checkLog.log file.??
Make sure that you have binding with only one logging framework. If you have more than one logging framework jar then you might NOT see output.
I had similar problem then found that, class path had
slf4j-simple-1.7.5.jar
as well aslog4j.jar
. So log output was getting written only on console. Removing first one from class path helped.Also check console, you should be getting a warning/error message.
I just tried the example you gave and it worked fine for me. There are several things that I'd check/try:
Check if you can write to the root of C: - write this instead:
to log to the current folder
Add a console logger to see whether it works in console:
When you run the application, you should see logging in the console and in the file.
Check that all sl4j libraries are in the path - you will need
slf4j-api
andslf4j-log4j12
jars on your classpathEnsure that
log4j.properties
is on the classpathHope this helps.