简体   繁体   English

log4j停止记录到文件,

[英]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 我在我的java应用程序中使用log4j,但经过一段时间没有抛出任何异常它停止了日志记录

my log4j configuration is as below. 我的log4j配置如下。

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. 我的文件追加器包含一些代码来执行zip操作并指定日志文件格式等等。

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? 任何人都知道这样的log4j相关问题吗?

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. 我回过头来意识到我已经改变了POM的依赖关系并做了一些谷歌搜索。

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 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. 比编写一个测试用例,其中一个线程每秒轮询一个INFO类型的日志消息。 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. 这是我的log4j属性文件的一个示例。 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. 然后,从这里的一个答案我添加了slf4j-log4j12库到依赖项,它开始再次工作。

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

Probably a very rare situation, but I once encountered a similar problem that was caused by use of a Cloner . 可能是一种非常罕见的情况,但我曾经遇到过使用Cloner引起的类似问题。 After cloning an object with log4j logging enabled, the logging just stopped working. 在启用log4j日志记录的情况下克隆对象后,日志记录才停止工作。 The solution was to exclude log4j classes from the cloning with: 解决方案是从克隆中排除log4j类:

cloner.dontClone(org.apache.log4j.Logger.class, org.apache.log4j.LogManager.class,)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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