Log4cxx DailyRollingFileAppender 未滚动

发布于 2025-01-06 06:33:19 字数 356 浏览 5 评论 0原文

我有一个仅在硬件触发时运行的应用程序。我们最近还添加了 log4cxx 的旧版 C++ 应用程序,用于生成日志以帮助调试罕见的生产问题。我们当然想要每日日志文件。

事实证明我们从来没有得到过滚动文件。

为了调试问题,我们将其设置为按分钟而不是按天滚动。我们发现,如果在从一分钟开始的几秒钟内调用该程序,文件就会滚动。如果在该分钟结束后超过 5 秒才调用,则不会发生翻滚。

在测试中,程序运行大约需要 5 秒。

如果需要的话,是否可以在程序启动时对文件进行 log4 翻转?

即,如果我们在第 6 分钟记录,然后直到第 50 分钟才再次运行,我们将在开始记录第 50 分钟之前滚动日志文件,而不是仅仅追加到第 6 分钟。

I have an application that only runs when triggered by hardware. An legacy c++ application that we recently added log4cxx too, to generate logs to help debug rare production issues. We of course wanted daily logfiles.

It turns out that we never got rolling files.

To debug the problem we set it roll over on the minute rather than the day. We found that if the program was called within a few seconds from the top of the minute, the file would roll over. If it was called more than 5 seconds after the top of the minute, roll over did not occur.

In testing the program takes roughly 5 seconds to run.

Is there anyway to have log4 rollover the file when the program starts, if needed?

i.e. If we logged at minute 6 and then don't run again until minute 50, we'll roll over the log file before we starting logging for minute 50, rather than just appending to minute 6.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

︶ ̄淡然 2025-01-13 06:33:19

DailyRollingFileAppender 在我的情况下也不起作用(在 log4cxx 0.10.0),所以我最终使用 RollingFileAppender 加上 TimeBasedRollingPolicy

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
      <param name="FileNamePattern" value="roll.%d{yyyy-MM-dd}.log"/>
    </rollingPolicy>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %t %c - %m%n"/>
    </layout>
    <param name="Append" value="true"/>
  </appender>
  <root>
    <priority value="ALL"/>
    <appender-ref ref="roll"/>
  </root>
</log4j:configuration>

点是 <强>不要指定,否则它不会滚动(它也无法识别StaticLogFileName 参数与原始 log4j 中相同)。

DailyRollingFileAppender didn't work in my case too (at log4cxx 0.10.0), so I ended up using RollingFileAppender plus TimeBasedRollingPolicy:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
      <param name="FileNamePattern" value="roll.%d{yyyy-MM-dd}.log"/>
    </rollingPolicy>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %t %c - %m%n"/>
    </layout>
    <param name="Append" value="true"/>
  </appender>
  <root>
    <priority value="ALL"/>
    <appender-ref ref="roll"/>
  </root>
</log4j:configuration>

Point is not to specify <param name="file"> or it won't roll over (also it doesn't recognize StaticLogFileName param as in the original log4j).

稀香 2025-01-13 06:33:19

尝试 {

log4j.rootLogger=debug, R

# Pattern to output the caller's file name and line number.

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern=test-%Y-%m-%d.log

}

Try {

log4j.rootLogger=debug, R

# Pattern to output the caller's file name and line number.

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern=test-%Y-%m-%d.log

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文