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 8430841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:41:46+00:00 2026-06-10T05:41:46+00:00

I am using Log4j as logging framework in a project I am working on.

  • 0

I am using Log4j as logging framework in a project I am working on. I have the following situation: Log4j is configured to write the logs into a log file. At some point, this log file is copied to another destination and deleted. Logging framework keeps working, but the logs are not written to the log file because it is deleted. Is there any way to tell Log4j to recreate the file and keep writing the logs into the log file.

Best regards,
Rashid

  • 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-06-10T05:41:47+00:00Added an answer on June 10, 2026 at 5:41 am

    I study the source of log4j and find log4j can’t create new log file, it just print the error message to system.err when the log file was deleted

        /** 
         This method determines if there is a sense in attempting to append. 
    
         <p>It checks whether there is a set output target and also if 
         there is a set layout. If these checks fail, then the boolean 
         value <code>false</code> is returned. */  
    
      protected   boolean checkEntryConditions() {  
        if(this.closed) {  
          LogLog.warn("Not allowed to write to a closed appender.");  
          return false;  
        }  
    
        if(this.qw == null) {  
          errorHandler.error("No output stream or file set for the appender named ["+  
                name+"].");  
          return false;  
        }  
    
        if(this.layout == null) {  
          errorHandler.error("No layout set for the appender named ["+ name+"].");  
          return false;  
        }  
        return true;  
      }  
    

    I think there are two workaround

    1. create another cron thread to monitor the log file
    2. add judge in getLog or getInstance (singleton), check the log file does exist, if not then init log4j
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project and we want to handle our logging using log4j.
We are using Log4j in our project for logging. I want to log some
I have been told to use log4j for my logging project,but before using log4j,
I have a project using common-logging and log4j , I want to change to
I have the following logging problem with several Java applications using log4j for logging:
I have a medium-size Java Web-application using Log4J as logging-framework. Right now i am
I am using log4j for logging. I have a requirement where the log files
I've using SLF4j as my logging framework, backed by log4j. My problem is that
I have discovered some issues in my program. I was using log4j for logging,
Using log4j, I used to have an appender that logs directly to one of

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.