Reputation: 723
I know there is several answers for how to set the file. Non have worked with me.
I'm trying to unifying several conf files for that I need to set the conf of log4j provided in slf4j-log4j12 into the configuration file provided as parameter of the program. Till now I tried by setting as parameter of the jvm like:
java '-Dlog4j.configuration=conf.cfg' -jar my.jar
I'm getting back:
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:ERROR Could not parse file [].
Setting programatically by:
System.setProperty("log4j.configuration",(new File( Configurator.getDefaultConfig().getString(Const.LoggingDefaultLoggingFile))).toURL().toString());
and
System.setProperty("log4j.configurationFile",(new File( Configurator.getDefaultConfig().getString(Const.LoggingDefaultLoggingFile))).toURL().toString());
Same result.
I tried using DOMConfigurator
but is for xml
I'm using properties
so no success.
I was searching how to reload the log4j but the give complex solution for making subscription for monitoring change and constant loading of changes.
I just want programatically change the configuration file once.
Till now, I was able to set the file just if I put it directly into the jar. But this by using a separated file with the default name.
Is there a way of loading the file directly int the Log4j (no shity system properties)? o there is a simple way of doing this better?
Upvotes: 1
Views: 3262
Reputation: 1474
log4j looking for log4j.properties
under WEB-INF\classes
PropertyConfigurator class,
example of usage:
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
// ...
public static final Logger log=Logger.getLogger(App.class);
// ...
PropertyConfigurator.configure("log4j.properties");
Upvotes: 1