Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SLF4J - Pulling Hair Out Trying To Configure

800581Nov 2 2009 — edited Nov 4 2009
Firstly, not sure if this is the correct sub-forum (or even correct forum) for this question, so sorry to any mod/admin if it needs moved.

OK, background on my situation. I'm writing an application and trying to use SLF4J 1.5.8 (with Log4J 1.2) for application logging. I am packaging my application (including all appropriate libraries) into a Fat Jar file and running it from the command line with the standard "java -jar <filename>". Now, that goes perfectly well if I include the "log4j.properties" file for Log4J in the jar file, but what I'd like to do is to keep the properties file outside of the jar file (so I can edit it without having to rebuild the jar) and also have several differently named configuration files which I can load when I initialise my application (the filename for the configuration I want to load being kept in a configuration file I can edit). This is not going so well. What I have tried to do is to user the System.setProperty() method to force Log4J to use the specific class (in the main method of my application before the logger is used) as such:

System.setProperty("log4j.configuration", log4JPropertiesFile.getAbsolutePath());

However, this doesn't appear to work because when I run my application I get the following warning:

log4j:WARN No appenders could be found for logger (examplepackage.Example).
log4j:WARN Please initialize the log4j system properly.

Can I accomplish what I want to, and if so how?

Secondly I have another problem related to the configuration of the properties file itself. I want to specify the file name for the log file with a relative path (e.g. just put the filename in there and for it to be written in the same directory where my jar file is being executed from), but everything I've seen in examples etc has shown that you need to specify the full path in the properties file. This isn't hugely convenient if you move the application for whatever reason. Is there a way to just specify a the log filename and have the log written in the folder the jar is executing from?

Hopefully you can help me out here before I pull all my hair out!

Edited by: amp88 on Nov 2, 2009 1:50 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2009
Added on Nov 2 2009
38 comments
1,008 views