Log4j dailyrollingfileappender文件问题 [英] Log4j dailyrollingfileappender file issues

查看:188
本文介绍了Log4j dailyrollingfileappender文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到了一个特殊的问题。
场景:我们有3台服务器,它们有一个组件的多个实例都将事务日志写入单个日志文件。我们使用log4j,服务器在Java 1.3中运行。 setAppend()传递为true,实现是DailyRollingFileAppender

We are encountering a peculiar problem. Scenario: We have 3 servers which with multiple instances of a component all writing transactional log to a single log file.We use log4j and the servers run in Java 1.3. setAppend() is passed true and implementation is DailyRollingFileAppender

问题:在午夜,我们期待当前日志文件以新文件名翻转并开始写入新文件。这在我们的测试设置(单服务器写日志)中运行良好。在生产中,在午夜,新文件被创建,新文件被写入,但滚动文件被删除

Problem: At midnight, we are expecting the current log file to roll over with a new file name and start writing to a new file. This is working well in our test setup (single server writing logs). In production, at midnight, new file is getting created where new logs are getting written but rolled over file is getting deleted

任何帮助都将受到高度赞赏,因为几天,我们无法获得问题的任何线索。

Any help will be highly appreciated as its been couple of days and we are not able to get any leads for the problem.

推荐答案

不应该日志来自许多进程的同一文件。 Log4j可以是线程安全的,但是如果可以的话,它不是过程安全的。它不能作为不同java进程之间的共享库。嵌入在一个java应用程序中的Log4j不知道任何其他任何一个。

You should not log to the same file from many processes. Log4j is thread-safe all right, but it's not process-safe, if I may say so; it does not work as a shared library among different java processes. Log4j embedded in one java application has no knowledge of any other one.

使用翻转它会导致你刚刚发现的问题:所有进程都会盲目地运行自己的翻转代码覆盖以前的内容(因为没有人期望任何内容)。

With rollover it causes the problem you've just discovered: all processes run their own rollover code, blindly overwriting the previous contents (because none of them expects any).

这里有一个可能的解决方案: Log4j登录到共享日志文件

A possible solution here: Log4j Logging to a Shared Log File

这篇关于Log4j dailyrollingfileappender文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆