简体   繁体   中英

log4j stopped logging to the file,

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 file 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

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.

您是否考虑过log4j仍在写入文件的可能性,但该文件已被自定义appender从其父目录中取消链接?

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,)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM