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
The procedure used is hard-coded in a static initializer block in LogManager
, so there doesn't appear to be a way to hook into it. The only place where it tells you what's going on is
LogLog.debug("Using URL ["+url+"] for automatic log4j configuration.");
but LogLog
itself is hard-coded to use System.out.println
for these messages so the only possibility I can see is to switch on debugging (-Dlog4j.debug=true
) and somehow hook in to System.setOut
before log4j is initialized, then parse the debug log message. But that is probably even more fragile than coding the config procedure yourself.
Even then, there may have been other programmatic configuration applied after the default configuration procedure (e.g. a Spring Log4jConfigListener
) - there isn't necessarily a single configuration URL as such.
It might be worth putting in a log4j feature request to factor out the config file search code into a static method that you can call from elsewhere, but that wouldn't help when you might have to cope with earlier versions of log4j.