You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Mark T. Buscher" <mb...@objectframe.com> on 2001/04/22 14:51:50 UTC

Question - PropertyConfigurator

Hello.  First things first... great work with Log4j.  Also, thank you to
anyone who takes a moment to answer my questions!  Now on to my questions:



I am integrating Log4j into a new project, but have not been able to resolve
an issue by reading the documentation (perhaps I haven't been reading in the
right places).  Does Log4j read the properties file from the hard drive each
and every time I call the following line of code?

     PropertyConfigurator.configure("MyConfigFile.properties");

I am presuming that PropertyConfigurator.configure() needs to be called only
once per thread, then everything is ready.  Do I understand correctly?

Second question:

In the following code, why is it OK for Category.getInstance("my.category");
to precede PropertyConfigurator.configure("MyConfigFile.properties"); ?
Doesn't getInstance() need the config file to be read in first?



import com.foo.Bar;

 import org.apache.log4j.Category;
 import org.apache.log4j.PropertyConfigurator;

 public class MyApp {

   static Category cat = Category.getInstance(MyApp.class.getName());

   public static void main(String[] args) {


     // BasicConfigurator replaced with PropertyConfigurator.
     PropertyConfigurator.configure(args[0]);

     cat.info("Entering application.");
     Bar bar = new Bar();
     bar.doIt();
     cat.info("Exiting application.");
   }
 }



Thanks and regards,
Mark Buscher
mbuscher@objectframe.com



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


Re: Question - PropertyConfigurator

Posted by Paul Glezen <pg...@atdial.net>.
"Mark T. Buscher" wrote:
> ... Does Log4j read the properties file from the hard drive each
> and every time I call the following line of code?
> 
>      PropertyConfigurator.configure("MyConfigFile.properties");
> 
> I am presuming that PropertyConfigurator.configure() needs to be called only
> once per thread, then everything is ready.  Do I understand correctly?
> 
Almost.  Yes, it does read the file from disk each time you call
configure, but you shouldn't have to call it for every thread.  Usually
just once per JVM should suffice.

> In the following code, why is it OK for Category.getInstance("my.category");
> to precede PropertyConfigurator.configure("MyConfigFile.properties"); ?
> Doesn't getInstance() need the config file to be read in first?
> 

In general it is not necessary to configure categories before calling
getInstance to instantiate them.  Most of the work in configuration
involve the creation of the necessary appenders, configuring them, and
associating them with the appropriate categories.  If the categories
exist already, because you've called getInstance, then fine.  Otherwise
they are created.

There are some cases where order does make a difference.  If your
configuration files specify a special category factory, then calling
getInstance before the configuration will not use the factory.

- Paul

-- 
Beware of bugs in the above code.  I have
only proved it correct, not tried it.
-Don Knuth

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