fcorange
fcorange

Reputation: 31

log4j not loading custom properties config

I'm trying to start up a java application from command line with the hope that it'll pick up the log4j config files in a different folder. Here is my folder structure:

However when I try running the program from /app for some reason log4j is not initializing properly:

-bash-4.2# pwd
/app
-bash-4.2# java -cp config:lib/* -Xmx1024M className
log4j:WARN No appenders could be found for logger(org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Surprisingly, if I move the config folder to /lib, and then try to start up the java program from there, it all seems to be working:

(updated folder structure):

Output:

-bash-4.2# pwd
/app/lib
-bash-4.2# java -cp config:* -Xmx1024M className
<Expected log message now shows up>

Inside my code I used PropertyConfigurator to load the config file:

PropertyConfigurator.configureAndWatch(loggingConfigFile)

Where logProperties is defined as

val loggingConfigFile = "config/custom.logging.properties"

Originally I thought the problem with the first scenario was with some kind of pathing issue, however when printing out System.getProperty("user.dir") during run time it seems that the program was indeed running under /app and that it should be able to load the config file from the defined path (i.e. /app/config/custom.logging.properties). Is there anything wrong with the setup?

Upvotes: 0

Views: 282

Answers (1)

Hridesh
Hridesh

Reputation: 71

EDIT: Application tries to find property files at run time path.

It's working in my case

enter image description here

For access properties value. Make ResourceBundle Object. Ex.:

private final ResourceBundle objRbLdap = ResourceBundle.getBundle("prperties file name");

Upvotes: 1

Related Questions