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.)
Share
If you are willing to use AspectJ LTW (load-time weaving), you can take a look at the static initialisation of
LogManagermentioned by Ian Roberts. In log4j 1.2.14 it looks like this: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:
In prose this code means:
OptionConverter.selectAndConfigureis called,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.