相关文章推荐
坏坏的丝瓜  ·  独家 | ...·  1 月前    · 
坏坏的丝瓜  ·  Orca 配置 GUI - ...·  6 月前    · 
坏坏的丝瓜  ·  反射获取Field - ALID Blog·  6 月前    · 
坏坏的丝瓜  ·  PostgreSQL 时间函数 ...·  9 月前    · 
坏坏的丝瓜  ·  groovy findall in list·  9 月前    · 
坏坏的丝瓜  ·  Simultaneous ...·  11 月前    · 
坏坏的丝瓜  ·  King's Uncle·  11 月前    · 
坏坏的丝瓜  ·  闲谈Monaco ...·  12 月前    · 
聪明伶俐的冰棍  ·  AttributeError: ...·  14 分钟前    · 
独立的柚子  ·  SpringBoot ...·  14 分钟前    · 
细心的蟠桃  ·  Spring Boot 2 实战:集成 ...·  14 分钟前    · 
高兴的蚂蚁  ·  mapstruct ...·  14 分钟前    · 
沉着的沙滩裤  ·  【feign】SpringCloud ...·  2 小时前    · 
眼睛小的生姜  ·  Feign的ErrorDecoder.Def ...·  2 小时前    · 
仗义的竹笋  ·  Spring Cloud Feign ...·  2 小时前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

log4net and log4j work as expected in this manner, so the bug is with log4cxx. :( Anyone else experiencing this problem with log4cxx? Shire Feb 18, 2012 at 22:24 # 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

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>
    <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).

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章
坏坏的丝瓜  ·  King's Uncle
11 月前