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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:44:40+00:00 2026-06-11T01:44:40+00:00

Log4j default initialization goes through a procedure to find and use a URL to

  • 0

Log4j default initialization goes through a procedure to find and use a URL to configure with. Afterward, how can you find out what URL was ultimately used, without having to code the same procedure yourself? (If you have to code it yourself, you might not get it exactly the same as log4j does, and also it might change in a future release.)

  • 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-11T01:44:42+00:00Added an answer on June 11, 2026 at 1:44 am

    If you are willing to use AspectJ LTW (load-time weaving), you can take a look at the static initialisation of LogManager mentioned by Ian Roberts. In log4j 1.2.14 it looks like this:

    static {
        // (...)
        // if there is no default init override, then get the resource
        // specified by the user or the default config file.
        if (override == null || "false".equalsIgnoreCase(override)) {
            // (...)
            URL url = null;
    
            // (...)    
            // If we have a non-null url, then delegate the rest of the
            // configuration to the OptionConverter.selectAndConfigure method.
            if (url != null) {
                LogLog.debug("Using URL [" + url + "] for automatic log4j configuration.");
                OptionConverter.selectAndConfigure(
                    url, configuratorClassName, LogManager.getLoggerRepository()
                );
            } else {
                LogLog.debug("Could not find resource: [" + configurationOptionStr + "].");
            }
        }
    }
    

    Obviously if a default URL could be determined then OptionConverter.selectAndConfigure(URL, ..) will be called at one point within the static block in order to initialise log4j with that URL.

    By means of AspectJ it is pretty simple to catch that method invocation:

    import java.net.URL;
    import org.apache.log4j.helpers.OptionConverter;
    import org.apache.log4j.LogManager;
    
    public aspect Log4jAspect {
        before(URL defaultURL) :
            within(LogManager) &&
            cflow(staticinitialization(LogManager)) &&
            call(* OptionConverter.selectAndConfigure(URL, ..)) &&
            args(defaultURL, ..)
        {
            System.out.println("log4j default URL = " + defaultURL);
        }
    }
    

    In prose this code means:

    • If we are within class LogManager and
    • within the control flow of the static class initialisation and
    • OptionConverter.selectAndConfigureis called,
    • then capture the first argument (the URL) and
    • print it to the console (you could just as well do something else).

    If there is no default URL, nothing will be printed. Instead of printing the URL you could assign it to a static member of any class or whatever you like.

    This is a solution for your problem, I tested it and it works. I would be happy to receive the bounty for answering your question, even though maybe the solution uses a technology you did not have in mind. But it solves the problem. 🙂


    Edit: It is also possible to explicitly intercept the log call in the case that no default URL is found, even though I do not think it is necessary. I just wanted to mention it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In weblogic I can configure in the console for the Serverlog to use log4j
In a web-module you can place the log4j.properties on the classpath and log4j's default
How do I configure jetty to use use log4j? I'm already using log4j in
I use a legacy library that writes logs using log4j. My default log4j.properties file
Log4J is failing for us generally after a few hours of use in our
Using log4j, I used to have an appender that logs directly to one of
I use log4j 1.2.16 regarding my dependency-report. my Conversion Pattern is '%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p
I know that log4j by default outputs to stderror. I have been capturing the
i'm starting with Log4J and i want to have a default log4j.properties in our
I'm trying out log4j in a simple test app. I create a new Java

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.