logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob Kjome" <h...@visi.com>
Subject Re: One .log file for two different applications
Date Tue, 24 Feb 2009 14:23:33 GMT
On Tue, 24 Feb 2009 01:11:13 -0800 (PST)
  alekoc <ale4349koc@mail.ru> wrote:
> Thank you, Arnauld
> I am new in Log4j. I just found it convenient for logging and decided to use
> it. I would like to ask you few questions, please.
> Why the shared/common directory relates to Log4j work? I had a hope that
> Log4j is a local re-enterable package and not important how do I call it. It
> should provide its main function – logging of process. Accordingly your
> response it is not exactly so.
> What means “loaded only once”? How can new web application use Log4j from
> another web application? I deploy them separately and each of them has its
> personal log4j.properties file. 

Log4j lives within the rules of Java classloading.  Just like any other 
library, where you put in in the classloader hierarchy matters.  If you want 
two apps to use the same Log4j instance, then you need to place log4j in a 
location where both apps can see it.  Place log4j under each app's WEB-INF/lib 
directory and not in some common location and you can't expect both to use a 
single instance of Log4j.  This is common sense.

A given instance of Log4j will perform auto-initialization once, as it runs in 
a static block of the LogManager class.  If each app has it's own Log4j 
instance, then each app will have auto-initialization performed for it.  If 
Log4j is in a common classloader, then auto-initialization will occur once, 
and only once no matter how many applications there are.

Of course, this doesn't mean you can't separate logging per/application using 
a single shared instance of Log4j.  I suggest you read the docs and search the 
lists for the concept of the Repository Selector.  By default, each instance 
of Log4j initializes its default Logger Repository.  If all apps use the 
default, then they'll only be using a single configuration and logging to 
appenders defined in that configuration.  However, by using a Repository 
Selector, one can store multiple configurations.  A Repository Selector 
implementation would contain logic on how each configuration (or Logger 
Repository) is identified and selected.  One common way is using JNDI.  
Another is by using classloaders (though this can cause classloading issues in 
environments where apps are restarted without shutting down the parent JVM, 
such as under a JEE container).

> What is “debug flag” you are talking about? How I can start to use/not use
> it?

When you run your app, add -Dlog4j.debug=true to the Java command line


> -- 
> View this message in context: 
> Sent from the Log4j - Users mailing list archive at Nabble.com.

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message