Manoj
Manoj

Reputation: 643

log4j - pointing to one out of multiple log4j.properties file

My code has a dependency on abc.jar file which internally uses log4j.jar and needs a configuration file. This configuration is used to set some of the required fields like ssl protocol, cert validate, port and also has a parameter, named debug, which is read by log4j.properties file (inside the abc.jar) to set the level of the logging. The value of the debug parameter is restricted to all or none. Also, the abc.jar file has its own (custom) Logger class. So whenever I create an object of org.apache.log4j.Logger class, it creates object of the (custom) Logger class inside the abc.jar file. I guess because of this Log4j is unable to read my log4j.properties file.

I want to use my own log4j.properties file so that I can specify the level of logging. How can I do this?

Upvotes: 1

Views: 1093

Answers (2)

Manuel S.
Manuel S.

Reputation: 421

Have you seen this post? Uses PropertyConfigurator to set the log4j path in any init() like method.

Upvotes: 0

Prim
Prim

Reputation: 2968

You can set the property log4j.configurationFile to set the path of your config file you want to use.

On command line, you can write -Dlog4j.configurationFile=<path>

Doing that disables automatic configuration and use your manually set file for configuration

Upvotes: 1

Related Questions