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 Kirk Benson <ki...@brokat.com> on 2001/01/10 15:27:37 UTC

Configuration in stateless objects?

I have an implementation question:

We have lots of code (servlets, JSPs, EJBs) that execute within an
application server as stateless client objects.  Therefore, we have no easy
access to the startup logic of the JVM from which to invoke the
PropertyConfigurator.configure() method.  I think the right way to do this
is to define a subclass of Category (similar to MyCategory) and implement a
static block within this class to configure the system.  As long as all
logging uses this derived Category subclass, then the first call to
getInstance() will configure the system.

Is there a better way to do this?


Re: Configuration in stateless objects?

Posted by Luke Blanshard <lu...@quiq.com>.
Kirk Benson wrote:

> ...  I think the right way to do this
> is to define a subclass of Category (similar to MyCategory) and implement a
> static block within this class to configure the system.  As long as all
> logging uses this derived Category subclass, then the first call to
> getInstance() will configure the system.
>
> Is there a better way to do this?

Another way is to have a class with static fields that hold your variables,
and put the startup logic in that class's initializer.  For example, we have a
class called DebugControl that contains statements like:

    public static final Category keyword = Category.getInstance( "keyword" );

All our logging code looks like this:

    DebugControl.keyword.debug( "something happened" );

HTH,
Luke


RE: Configuration in stateless objects?

Posted by Kirk Benson <ki...@brokat.com>.
I now have what I need.  I was not aware of the reference part of the URL,
which is the "missing link".

By writing my own configuration class, I can configure using the Properties
file AND the configureAndWatch() method.

I might suggest that the javadoc for this feature be easier to find.  The
information on the DEFAULT_CONFIGURATION_KEY is documented for Category,
while the information on the URL reference is documented in
OptionConverter.selectAndConfigure().  Finally, the user needs to be aware
that the classname specified in the url#reference must implement Interface
Configurator.

Minor nit: the javadoc for OptionConverter has typo: convinience

This package is really cool - thanks

-----Original Message-----
From: Ceki Gulcu [mailto:cgu@urbanet.ch]
Sent: Wednesday, January 10, 2001 7:48 PM
To: LOG4J Users Mailing List
Cc: :
Subject: Re: Configuration in stateless objects?



Kirk,

I suppose you are aware of the static initialization procedure in
Category.java? When the Categroy class is loaded it will search for the
file "log4j.properties" in the classpath.

Furthermore, you can set the log4j.configuration system value to a file
path or a URL to parse a different file then "log4j.properties"  If the URL
ends in .xml then the DOMConfigurator will be used to parse the file.

There is an additional twist: if the URL has a reference part, then that
will be used as the class name of the configurator class.

For example if you invoke your application using the command line

      java
-Dlog4j.configuration=file:/temp/myconfig.xyz#com.myCompany.myConfigurator
someCompany.someApplication

     then the log4j will be configured by a new instance of
com.myCompany.myConfigurator using the file referenced by
     file:/temp/myconfig.xyz.

Does this help? Ceki

At 09:27 10.01.2001 -0500, you wrote:
>I have an implementation question:
>
>We have lots of code (servlets, JSPs, EJBs) that execute within an
>application server as stateless client objects.  Therefore, we have no easy
>access to the startup logic of the JVM from which to invoke the
>PropertyConfigurator.configure() method.  I think the right way to do this
>is to define a subclass of Category (similar to MyCategory) and implement a
>static block within this class to configure the system.  As long as all
>logging uses this derived Category subclass, then the first call to
>getInstance() will configure the system.
>
>Is there a better way to do this?


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


Re: Configuration in stateless objects?

Posted by Ceki Gulcu <cg...@urbanet.ch>.
Kirk,

I suppose you are aware of the static initialization procedure in 
Category.java? When the Categroy class is loaded it will search for the 
file "log4j.properties" in the classpath.

Furthermore, you can set the log4j.configuration system value to a file 
path or a URL to parse a different file then "log4j.properties"  If the URL 
ends in .xml then the DOMConfigurator will be used to parse the file.

There is an additional twist: if the URL has a reference part, then that 
will be used as the class name of the configurator class.

For example if you invoke your application using the command line

      java 
-Dlog4j.configuration=file:/temp/myconfig.xyz#com.myCompany.myConfigurator 
someCompany.someApplication

     then the log4j will be configured by a new instance of 
com.myCompany.myConfigurator using the file referenced by
     file:/temp/myconfig.xyz.

Does this help? Ceki

At 09:27 10.01.2001 -0500, you wrote:
>I have an implementation question:
>
>We have lots of code (servlets, JSPs, EJBs) that execute within an
>application server as stateless client objects.  Therefore, we have no easy
>access to the startup logic of the JVM from which to invoke the
>PropertyConfigurator.configure() method.  I think the right way to do this
>is to define a subclass of Category (similar to MyCategory) and implement a
>static block within this class to configure the system.  As long as all
>logging uses this derived Category subclass, then the first call to
>getInstance() will configure the system.
>
>Is there a better way to do this?