You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Tomcat与Log4j时每日日志文件停止生成的技术求助

Troubleshooting Log4j DailyRollingFileAppender Stopped Generating Daily Logs

Hey Leo, sorry to hear your daily logs stopped rolling—let’s break down the most common issues and fixes for this scenario with Tomcat and Log4j 1.x:

Key Checks to Perform

1. Verify Directory Permissions

First, make sure the Tomcat runtime user has read/write/execute permissions on the logs/debuglog/ directory.

  • On Linux/Unix, run this command to check access:
    ls -ld logs/debuglog/
    
    Ensure the user running Tomcat (usually tomcat or your system user) has rwx permissions here.
  • On Windows, right-click the folder → Properties → Security tab, confirm the Tomcat service user has modify permissions.

2. Complete Your DailyRollingFileAppender Configuration

Looking at your provided config, you’re missing the layout setup for the dailyfile appender—this can cause Log4j to fail initializing the appender silently. Add these lines to your properties:

log4j.appender.dailyfile.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyfile.layout.ConversionPattern=%-5p %c %M:%L %m%n

Without a valid layout, the appender won’t write any logs at all.

3. Check Version Compatibility & Known Bugs

Log4j 1.x’s DailyRollingFileAppender has known bugs in older releases (e.g., date parsing errors, time zone mismatches, file locking issues).

  • Ensure you’re using the latest stable Log4j 1.x version (1.2.17) in your app’s WEB-INF/lib directory.
  • If you’re running a newer JDK (1.8+), some older Log4j versions might have compatibility gaps that break rolling logic.

4. Look for Initialization Errors

Check Tomcat’s core logs for Log4j startup failures:

  • On Linux, this is typically catalina.out in the Tomcat logs directory.
  • On Windows, check localhost.log or catalina.log.
    Watch for lines like:
ERROR log4j: Failed to activate appender named [dailyfile].

These messages will directly tell you why the appender isn’t working (e.g., permission denied, missing layout, invalid date pattern).

5. Validate the Date Rolling Pattern

By default, DailyRollingFileAppender uses .yyyy-MM-dd as the date pattern, but explicitly setting it can avoid timezone or parsing glitches. Add this line to your config:

log4j.appender.dailyfile.DatePattern='.'yyyy-MM-dd

Also confirm your server’s system time and timezone are correct—if the time jumps backward (e.g., due to NTP sync), Log4j might skip rolling to avoid overwriting existing files.

6. Rule Out Log Framework Conflicts

Tomcat uses java.util.logging (JUL) by default, which can conflict with Log4j if not properly isolated:

  • Make sure your web app only includes the Log4j 1.x JAR in WEB-INF/lib (no conflicting SLF4J bridges or other logging frameworks unless explicitly configured).
  • Check if Tomcat’s conf/logging.properties is overriding Log4j’s behavior—you might need to disable JUL for your app or use a bridge library.

7. Test Manual Rolling

In a test environment, try these steps to trigger rolling:

  1. Restart Tomcat and check if a new log file (with the current date suffix) is created.
  2. Manually advance the system date by one day, then write a debug log entry—verify if a new rolled file is generated.

If none of these steps resolve the issue, share any error messages from catalina.out or enable temporary Log4j debug logging (add log4j.debug=true to your properties file) for deeper troubleshooting.

内容的提问来源于stack exchange,提问作者Leo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:56:35