Michael
Michael

Reputation: 806

Automatic log4j configuration and bundleresource

Two issues / questions:

1) In many of the log4j threads / forums / etc., I am seeing the results of defining the log4j.debug containing log4j configuration file references prefixed with "file:" as shown below:

log4j: Using URL [file:/data/app/conf/log4j.properties] for automatic log4j configuration.

In the code I am updating (authored by another developer now working someplace else), I am seeing:

log4j: Using URL [bundleresource://23/log4j.properties] for automatic log4j configuration

What/where is the "bundleresource" as shown above? I am thinking this is a dedicated resource Eclipse plug-in that I have been unable to identify.


2) This question stems from a larger issue of not being able to load a log4j configuration file without explicitly inserting it into the command line arguments of the JVM (e.g., -Dlog4j.configuration). I am replacing an Eclipse plugin-based application on a test server that does not have this command line argument specified in a start up script and is able to correctly fire up with log4j being initialized correctly. When I go to replace this application with the latest build from our source repository, the application fails to locate the log4j configuration file. Any thoughts on why the first application can start up and locate the log4j configuration file while the second (newer) application cannot?

Any help would be greatly appreciated.

Thanks!



Update / Edit

Output from the application with log4j.debug defined:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@9fe666.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@9fe666 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].

Upvotes: 0

Views: 810

Answers (1)

Nthalk
Nthalk

Reputation: 3833

You can load a properties file for Log4j by first loading the properties, then tossing it into log4j's property configurator:

Properties props = new Properties();
FileInputStream fis = new FileInputStream("mylog4j.properties");
props.load(fis);
fis.close();
PropertyConfigurator.configure(props);

The bundleresource seems like a library specific thing. I recommend using grep on the sourcecode:

grep -irn ./ -e "bundleresource"

Upvotes: 1

Related Questions