1

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?

Manoj
  • 644
  • 12
  • 21

2 Answers2

1

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

Prim
  • 2,880
  • 2
  • 15
  • 29
  • I tried, but it is not working. How can I verify if that file is read? – Manoj Jan 05 '16 at 09:34
  • Are you sure to set the correct path for the file according to the working directory ? You can try to use full absolute path. I see no other reason this is not working. Except if is re-set/configure programmatically in source code – Prim Jan 05 '16 at 10:16
0

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

Community
  • 1
  • 1
Manuel S.
  • 411
  • 8
  • 21