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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:11:28+00:00 2026-06-10T20:11:28+00:00

Some Log4j Configurators have a configureAndWatch() method, that starts a Thread to watch the

  • 0

Some Log4j Configurators have a configureAndWatch() method, that starts a Thread to watch the file used for configuration (XML file or properties file) and trigger a reconfigure if the file changes.

However, if you rely on the Log4j default initialization procedure, you never get a chance to call configureAndWatch(). You don’t even know the file that was used to configure with (it might not even be a file.)

Is there a good way to get configureAndWatch() style behavior, allowing changing of the log configuration on the fly, while still using the default initialization procedure? I am assuming that your configuration URL ultimately resolves to a file that can be watched, as a URL on another server would probably not be something you would want to pull every 60 seconds.

(I see that the configureAndWatch() method is not safe in a Java EE environment because of the separate thread, and I see that some app servers have their own mechanism for watching the log4j configuration file, but the program I am working on at the moment is not running in Java EE .)

  • 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-10T20:11:30+00:00Added an answer on June 10, 2026 at 8:11 pm

    I’ve scrapped everything in the answer before and started over now that I better understand what you want.

    The following paragraph describes the real sequence that log4j uses to determine what the log4j config file name is. This code tries to follow those rules.

    http://logging.apache.org/log4j/1.2/manual.html#defaultInit

    It determines what log4j configuration file to use and then sets up the PropertyConfigurator using the file it found. This will only work if the file is located on the file system. It will not work if the file is inside a jar or at a remote HTTP URL.

        String prop = System.getProperty("log4j.configuration");
        if (prop == null) prop = "log4j.properties";
        URL log4jConfig = Loader.getResource(prop);
        if (log4jConfig.getProtocol().equalsIgnoreCase("file")) {
            PropertyConfigurator.configureAndWatch(log4jConfig.getFile().substring(1), 10000);
        }
        else {
            // cannot monitor if file changed because URL is not a file
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have log4j.properties file, that logs more than I expect,in particular, it logs events for
I'm having some problems putting my log4j.properties file on classpath. I can use it
i'm trying to convert my log4j.properties into log4j.xml because i need to use some
I have a spring application that has configured log4j (via xml) and that runs
Packaging a log4j configuration file in a NetBeans Platform application apparently requires some thinking
I have implement a log4j.xml file having two loggers. Both EventLogger and ErrorLogger logged
I have some problems with setting Threshold in properties file. I created two files:
If I make a change to a Log4j configuration file, do I have to
During a setup program, a configuration file (log4j.properties) needs to be modified. One line
I have discovered some issues in my program. I was using log4j for logging,

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.