axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hansen, Richard" <Richard.Han...@westgroup.com>
Subject RE: Issue: remove calls to BasicConfigurator in Options.java and Axis Engine.java
Date Tue, 02 Oct 2001 14:11:12 GMT
There is no log4j API to find out if log4j has been configured. Below is
some code I saved from the log4j mail list that supposedly can tell if
configuration has already been done. I have not tried it, so I cannot vouch
for it usefulness. I beleive it looks for appenders and category objects.

On another note, configuring log4j multiple times is not necessarily
harmful. In a mail I saw in the log4j list this morning Ceki Gülcü says:

"If a configuration file is reloaded, then any category mentioned in the
config file will have its appenders closed and removed. The duplication will
not occur."

Personally I am very interested in this. I have a servlet that inits log4j.
I do this so that I can call the configureAndWatch() method. That way log4j
will watch the config file for changes and dynamically relaod it. When you
let log4j find and load log4j.properties you do not get this behavior. 

Rick Hansen

------------------------------------------------------------------

static {
// if it appears that log4j is not configured, then set up
// a default configuration so that at least warning or above end
// up in the console.
  if (!isConfigured()) {			
    doBaseConfigure();
  }
}

/** This code (from Ceki Gülcü) checks to see if there are any
appenders defined for log4j which is the definitive way to tell 
if log4j is already initialised **/
private static boolean isConfigured() {
  Enumeration enum = Category.getRoot().getAllAppenders();

  if (!(enum instanceof org.apache.log4j.helpers.NullEnumeration)) {
    return true;
  }
  else {
    Enumeration cats =  Category.getCurrentCategories();
    while (cats.hasMoreElements()) {
      Category c = (Category) cats.nextElement();
      if (!(c.getAllAppenders() instanceof
org.apache.log4j.helpers.NullEnumeration))
        return true;
	}
  }
  return false;
}
	
private static void doBaseConfigure() {
  // set up the default configuration
  Layout layout = new PatternLayout("%d{ABSOLUTE} %-5p %c{1}%x : %m%n");
  Appender appender = new ConsoleAppender(layout);
  Category root = Category.getRoot();
  root.addAppender(appender);
  root.setPriority(Priority.WARN);
  root.warn("Log4j not configured, base configuration
            (ConsoleAppender/WARN) applied to root category");
}

> -----Original Message-----
> From: Glen Daniels [mailto:gdaniels@macromedia.com]
> Sent: Tuesday, October 02, 2001 8:51 AM
> To: 'axis-dev@xml.apache.org'
> Subject: RE: Issue: remove calls to BasicConfigurator in Options.java
> and Axis Engine.java
> 
> 
> 
> Yep, we never finished dealing with this issue.
> 
> The question is basically this - we want people to be able to use our
> toolkit with minimal setup, and in fact NO setup in most 
> cases.  So we don't
> want to force them to have to build a log4j.properties file 
> and drop it
> somewhere.  The ideal thing would be able to specify 
> something like "here's
> my default hardcoded log4j config, which you should use only 
> IF the default
> initialization process failed." - but I didn't see any way to 
> do that.  Is
> there a way to query if log4j has already been configured?
> 
> Maybe the answer is to put a default log4j.properties at the 
> top level of
> the axis.jar file, which we can reasonably expect will be on 
> the classpath.
> The problem then becomes getting your own log4j.properties to 
> override that
> one requires making sure it shows up first on the classpath, 
> which I'm not
> sure you can guarantee in app server environments.
> 
> Thoughts?  I'd love to get this nailed.
> 
> --Glen
> 
> > -----Original Message-----
> > From: Mark Roder [mailto:mroder@wamnet.com]
> > Sent: Monday, October 01, 2001 10:48 PM
> > To: 'axis-dev@xml.apache.org'
> > Subject: Issue: remove calls to BasicConfigurator in 
> Options.java and
> > Axis Engine.java
> > 
> > 
> > 
> > Options.java and AxisEngine have the following code segment:
> > 
> >     static {
> >         BasicConfigurator.configure();
> >         Category.getRoot().setPriority(Priority.FATAL);
> >     }
> > 
> > This segment should be removed.  It strongarms the log4j setup and
> > applications can not change the behavior.
> > 
> > I am trying to use axis in a client application talking to an 
> > existing soap
> > service.  I am using the log4j.properties file in the 
> > classpath to setup
> > log4j in the default/lazy method.  I was not getting any of 
> my logging
> > output because axis did the above calls.
> > 
> > More information on log4j's default initialization procedure 
> > how to setup
> > log4j can be found at
> > http://jakarta.apache.org/log4j/docs/manual.html#defaultInit
> > 
> > Later
> > 
> > Mark
> > 
> 

Mime
View raw message