English 中文(简体)
log4j 文件助手在对日志文件旋转时不切换到新文件
原标题:log4j fileappender doesn t switch to the new file when logrotate rotates the log file

<强度 > 全文:

我想使用log4j 来将审计相关日志写入特定的日志文件, 不如使用 audit.log 。 我不想使用 syslogappender( udp based), 因为我不想容忍数据丢失。 此外, 当文件达到一定大小时, 我正使用对数来旋转审计 。 log

<强 > 问题:

我遇到的是,当对账旋转文件审计时, log to countal.log.1, log4j 继续写给审计.log.1, 而不是写给审计.log.1。

<强 > 可采用的方法:

  1. 我知道我可以使用滚动文件应用程序来进行日志旋转,而不是使用日志旋转,所以当滚动文件应用程序滚动文件时,它会毫无麻烦地切换到新文件。但是,我之所以不能使用滚动文件应用程序,是因为我想在旋转发生后使用对调的日志旋转功能来触发一些脚本,而滚动文件应用程序无法提供这些脚本。

  2. 另一个绝望的方法是自己写一个为log4j定制的附加器, 关闭日志文件( audit.log.1), 并在检测文件旋转时打开新的文件( audit.log) 。

  3. 我从未使用外部旋转FileAppender, 但如果可以使用对数旋转柱向外部旋转FileAppender发送信号, 并让log4j知道文件被旋转, 并开始写入新文件吗?

" 强 " 问:

或者我还有其他办法解决这个问题吗?

最佳回答

检查 logrotate s copytruncate 选项, 可能有助于处理以下案例:

copytruncate
       Truncate the original log file to zero size  in  place
       after  creating  a copy, instead of moving the old log 
       file and optionally creating a new  one.   It  can  be  
       used  when  some  program  cannot be told to close its 
       logfile and thus might continue writing (appending) to
       the  previous  log file forever.  Note that there is a
       very small time slice between  copying  the  file  and 
       truncating  it,  so  some  logging data might be lost.
       When this option is used, the create option will  have
       no effect, as the old log file stays in place
问题回答

暂无回答




相关问题
Specify time zone of log4j s date

Is it possible to specify the time zone that log4j will use? I need the dates in the log file to be a different time zone than the application s. log4j s PatternLayout uses SimpleDateFormat. ...

java wrapper around log4j logger and java.util.logging

I am writing a library. The library can be used by applications that use log4j loggers and java.util.logging loggers. So, I wrote a quick wrapper class, that encapsulates both loggers. I allow the ...

Grails log4j configuration

I ve repeatedly had problems with the DSL introduced by Grails in version 1.1 for configuring Log4J. My current configuration looks like this: log4j = { debug com.mypackages ...

Creating daily logs with Log4j?

What configuration values are needed to setup Log4j to use the following pattern? MyApp-Mon.log MyApp-Tue.log MyApp-Wed.log Etc With each file containing the days log. This sounds easy enough to do ...

Overriding log4j settings at deploy time

For an application which is deployed on a large number of machines I took the decision to deploy a standard log4j.xml file with the application package, just to make sure that have the same settings ...

How to validate Java logging properties files?

I have a basic facility for allowing users to remotely apply changes to the logging files in my application. Some logs are configured using java.util.logging properties files, and some are configured ...

How do you Change a Package s Log Level using Log4j?

I ve encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs when log level for org.apache.axiom is DEBUG so a ...

热门标签