-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: please help with log4j
PostPosted: Tue Jul 28, 2009 5:23 am 
Newbie

Joined: Tue Jul 28, 2009 5:05 am
Posts: 2
Hello everybody.

I am using log4j in my project. Everything works fine if i leave my log4j.properties (where i have all my appenders) just inside my \src folder. But what i want to do is to have it as an external file, so i can stop my program, modify the properties file and start it again (for example to change the logging level from trace to info).
To achieve this i:

-)modified build.xml to copy the property file in the dist folder:
<target name="-pre-compile">
<copy file="log4j.properties" tofile="./build/log4j.properties"/>
<copy file="log4j.properties" tofile="./dist/log4j.properties"/>
</target>

-)I am initializing the properties of log4j in my logging class (static initializer called once):
PropertyConfigurator.configure(getInstallationFolder()+"\\log4j.properties");
//getInstallationFolder() give me the dist folder

This way everything works, can change the file and restart the program, and can see that the log format has changed. But hibernate does not find the property file, or at least is looking for it somewhere else. In fact i get the usual message:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.


Basically how can i say to hiberante where to look for that file? Libraries and everything else is configured right, in fact if i leave the property file in the \src (classpath) the loggings of hibernate are fine.
Any help is welcome, thank you!!!!


Top
 Profile  
 
 Post subject: Re: please help with log4j
PostPosted: Thu Jul 30, 2009 4:36 am 
Newbie

Joined: Tue Jul 28, 2009 5:05 am
Posts: 2
Solved it. As from documentation, hibernate is looking for a file "log4j.properties" in the classpath.

So the thrick is to specify the property loader before any hibernate action is called; to be safe i put as first call in my program, like this:

PropertyConfigurator.configure(getInstallationFolder()+"\\log4j.properties");

In this way the property file is not inside the jar, and i don't have to recompile if I just want to change the levels of logging.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.