-->
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.  [ 6 posts ] 
Author Message
 Post subject: Logger for Hibernate in multiple applications
PostPosted: Thu Feb 01, 2007 5:33 pm 
Newbie

Joined: Thu May 11, 2006 5:00 pm
Posts: 5
We are facing a very peculiar situation. We have multiple applications and/or components running in the same Application Server. Few of them use Hibernate. Currently all the hibernate messages go to one log file irrespective of the application/component that used it. Hence it gets very difficult for us to parse through and find out an error or message pertaining to a particular application or to trace it along with the application's log contents.

We would want the Hibernate log specific to each of the applications to be written to the corresponding application's log file. Is this possible? If so how to do this?

-Suchi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 9:16 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Put the appropriate log4j.properties in the root of each application's classpath. Specify a different set of appenders in each properties file.

Read your log4j docs for how to do this.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 4:05 pm 
Newbie

Joined: Thu May 11, 2006 5:00 pm
Posts: 5
Unfortunately, all the applications share the same logging mechanism and they all run under the same JVM. The log4j.configuration system property has been set in the JVM level to point to one common properties file. This arrangement cannot be changed for many applications depend on this and changing this means asking all the older applications to add a log4j.properties in their classpath.

Is there any other way this could be managed?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 4:06 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
log4j can be configured to use a different logfile for every class, package, group of packages, or anything. You can fix it for hibernate without affecting any other application. Just edit the relevant log4j.properties file after reading up on how to do it.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 3:45 pm 
Newbie

Joined: Thu May 11, 2006 5:00 pm
Posts: 5
This is what I found in log4j FAQ for my question. This is exactly my problem and the last solution provided is what would work for me. But in order to do this, I think ( I am not sure) there might be some code change necessary within Hibernate Source code

3.1 Can the outputs of multiple client request go to different log files?
Many developers are confronted with the problem of distinguishing the log output originating from the same class but different client requests. They come up with ingenious mechanisms to fan out the log output to different files. In most cases, this is not the right approach.

It is simpler to use a nested diagnostic context (NDC). Typically, one would NDC.push() client specific information, such as the client's hostname, ID or any other distinguishing information when starting to handle the client's request. Thereafter, log output will automatically include the nested diagnostic context so that you can distinguish logs from different client requests even if they are output to the same file.

See the NDC and the PatternLayout classes for more information. The NumberCruncher example shows how the NDC can be used to distinguish the log output from multiple clients even if they share the same log file.

[b]For select applications, such as virtual hosting web-servers, the NDC solution is not sufficient. As of version 0.9.0, log4j supports multiple hierarchy trees. Thus, it is possible to log to different targets from the same logger depending on the current context[/b].


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 5:10 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I infer from that post that you're talking specifically about log messages from org.hibernate and below, as opposed to messages from your classes that use hibernate. I've never done anything like that, but it seems that it is possible if you use LogManager.setRepositorySelector(). You shouldn't have to touch already-compiled code, you just need to write a class that can determine what application or context it is operating in (possibly by looking at its current stacktrace?) and return a log4j Hierarchy based on that.

Note that the way that this is done is different now than it was in 0.9.0. Check out the Log4j lavadocs for more info.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.