DailyRollingFileAppender,丢失前一天的数据
第一天 计划开始并全天进行。日志按预期写入
第 2 天 午夜过后,当天的第一个活动发生(cron 中) 我的情况)该活动被记录,并且第一天的所有数据都会丢失。 此活动记录为第 1 天活动
log4j.rootLogger=DEBUG, R
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = ../log/ooo.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
示例:
在 ooo.log.2011-10-20
中,我希望找到 10-20 的活动 相反,我看到 10-21 的前几秒
我期望行为,如 规范
'.'yyyy-MM-dd 每天午夜滚动。三月的午夜 2002 年 8 日,/foo/bar.log 将被复制到 /foo/bar.log.2002-03-08。 3 月 9 日的日志将输出到 /foo/bar.log 直到 第二天就会结转。
此外,请查看时间戳。它看起来是随机的,与调用我的 cron 时的分钟标记一致。不管它做什么,appender 的行为都与其描述不一致。
这是怎么回事?请帮助我理解并纠正。
Day 1 Program start and works all day. Log is written as expected
Day 2 Past midnight when first activity for the day happens (a cron in
my case) THAT ACTIVITY is recorded and all data for the Day 1 is lost.
This activity is recorded as Day 1 activity
log4j.rootLogger=DEBUG, R
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = ../log/ooo.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
Example:
In a ooo.log.2011-10-20
i expect to find activity for 10-20
Instead i see first few seconds of 10-21
I expect behavior , as defined by the specification
'.'yyyy-MM-dd Rollover at midnight each day. At midnight, on March
8th, 2002, /foo/bar.log will be copied to /foo/bar.log.2002-03-08.
Logging for the 9th day of March will be output to /foo/bar.log until
it is rolled over the next day.
Additionally, take a look at the timestamps. It appears to be random is consistent with the minute mark when my cron is called. Regardless of what it does though, appender's behavior is not consistent with its' description.
What's going on here? Please help me understand and correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这也可能是程序的多个实例记录到同一文件的症状;请参阅此处和其他答案。
真的。翻转不会“按时”发生,而是在翻转时间标记之后发生第一个记录的语句(因此是您的文件时间戳)。并且不检查需要重命名翻转部分的文件名是否可以自由使用。
This may also be a symptom of multiple instances of a program logging to the same file; see more here and in other answers.
True. Rollover does not happen "on the hour", but with the first logged statement AFTER the rollover time mark (hence your file timestamps). And there is no check if the name of the file to which the rolled over part needs to be renamed is free to use.