I am using log4j in my java application, but after some time without throwing any exception it stopped logging
my log4j configuration is as below.
log4j.rootLogger=INFO,FILE
log4j.appender.FILE=com.test.TestFIleAppender
log4j.appender.FILE.MaxFileSize=20MB
log4j.appender.FILE.MaxBackUpIndex=200
My fi开发者_StackOverflowle appender contains some code to do the zip operation and to specify the log file format and all.
This was logging fine for some time, but suddenly stopped logging , no exception also thrown
can any body tell me what can be the issue?
any body know any log4j related issues like this?
This happened to me. Working one day and then not working the next. I went back and realized I had changed the POM dependencies and did some googling.
When I corrected this issue, my logging returned. I would make sure you have the following artifacts in sync:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
http://www.slf4j.org/manual.html
It is difficult to answer, why your logging is stopping.
First, check the hard disk space, whether this is full.
Than write a testcase in which a thread is polling a logging message of type INFO every second. Than you could check whether this is a space or memory issue.
Please notice: When you programm is waiting somewhere and no thread or action is working, you will not see any loging message. Please check, by debugging, whether a code line is executed in a loop (or as you expected to see messages) in which a logging message should be shown.
This is an example of my log4j properties file. May be is is helpful:
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) [%c] - %m%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=C:/log/client.log
log4j.appender.logfile.MaxFileSize=5MB
log4j.appender.logfile.MaxBackupIndex=0
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
Have you considered the possibility that log4j is still writing to a file, but that file has been unlinked from its parent directory by your custom appender?
It happened to me after adding sardine library to my dependencies. Then, from one of answers here I added slf4j-log4j12 library to the dependencies and it started to work again.
Probably a very rare situation, but I once encountered a similar problem that was caused by use of a Cloner. After cloning an object with log4j logging enabled, the logging just stopped working. The solution was to exclude log4j classes from the cloning with:
cloner.dontClone(org.apache.log4j.Logger.class, org.apache.log4j.LogManager.class,)
精彩评论