Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3339326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:28:45+00:00 2026-05-18T00:28:45+00:00

The normal behavior of the Log4j RollingFileAppender is to roll when the first log

  • 0

The normal behavior of the Log4j RollingFileAppender is to roll when the first log message occurs on a different day, but some feel warm and fuzzy with empty logfiles for each date, even if nothing occurred. Is there a way to force it to roll after midnight without writing dummy messages to the log?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:28:46+00:00Added an answer on May 18, 2026 at 12:28 am

    I’ve looked at this code very closely – the simple answer is ‘no’. The rollover is triggered as part of the doAppend() flow on the Appender – the only way to trigger it is to log something.

    You could fake this with cron: just have a cron script touch the file for tomorrow at like 11:58. That will get you the empty logfile behavior you’re looking for.

    Here’s the code that implements the rollover function:

    void rollOver() throws IOException {
    
        /* Compute filename, but only if datePattern is specified */
        if (datePattern == null) {
          errorHandler.error("Missing DatePattern option in rollOver().");
          return;
        }
    
        String datedFilename = fileName+sdf.format(now);
        // It is too early to roll over because we are still within the
        // bounds of the current interval. Rollover will occur once the
        // next interval is reached.
        if (scheduledFilename.equals(datedFilename)) {
          return;
        }
    
        // close current file, and rename it to datedFilename
        this.closeFile();
    
        File target  = new File(scheduledFilename);
        if (target.exists()) {
          target.delete();
        }
    
        File file = new File(fileName);
        boolean result = file.renameTo(target);
        if(result) {
          LogLog.debug(fileName +" -> "+ scheduledFilename);
        } else {
          LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
        }
    
        try {
          // This will also close the file. This is OK since multiple
          // close operations are safe.
          this.setFile(fileName, false, this.bufferedIO, this.bufferSize);
        }
        catch(IOException e) {
          errorHandler.error("setFile("+fileName+", false) call failed.");
        }
        scheduledFilename = datedFilename;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if this is server related or normal behavior, but I thought I'd
I know that when overflow occurs in C/C++, normal behavior is to wrap-around. For
AsyncFileUpload control start uploading file as soon as user select file. But normal behavior
What is the normal behavior in Objective-C if you call a method on an
Generating normal columnar data in excel file is quite easy but does any one
In normal sql I could do joins on tables in different databases as long
question comes up from some behavior i'm seeing. we're using mysql 5.1.36, xtradb release
Looking to have some alerts/prompts pop up in my iPhone web app but I
the normal behavior of urllib/urllib2 is if an error code is sent in the
When Velocity encounters an undefined reference, its normal behavior is to output the image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.