logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Kristensen <akristen...@dynamicsoft.com>
Subject Re: How about log4j.layout in configure file?
Date Wed, 21 Mar 2001 18:51:47 GMT
Jin,

I think what you ask for makes a lot of sense but that it might be part
of a more thoroughly reworked property configurator, which also handles
configuration of Categories, Appenders, Layouts, ErrorHandlers and
Filters in a consistent, simple, and powerful manner.

Let me try and outline how I think this can be done in an extension of
the JavaBeans style configuration recently introduced. In the scheme
described below the configurator doesn't even know about the specifics
of these log4j components but just knows how to configure arbitrary
objects.

As an example, an appender might have a property "layout" with value
"${mylayout}" and a corresponding setter of the form

  public void setLayout(Layout)

The configurator would see this and would try and create the "mylayout"
object according to the properties file, e.g.

log4j.mylayout=org.apache.log4j.PatternLayout
log4j.mylayout.ConversionPattern=%-5p - %c{2}: %m%n
log4j.mylayout.DateFormat=ISO8601

so it would load the class "org.apache.log4j.PatternLayout", instantiate
it and check that it matches the argument to the setter (Layout). It
does match as PatternLayout extends Layout, so the configurator
continues to configure the mylayout object recursively. When $mylayout
is fully configured the configurator passes it to setLayout() on the
appender.

The beauty of this scheme is that it's generic - there needs to be very
little log4j specific code, if any. This also makes it simple.
Configuration of error handlers, filters comes for free. The file format
would have to change, though, to make the syntax more uniform. For this
reason I think this is a new and separate configurator rather than a fix
of the existing one.

Cheers,
Anders


Jin Zhao wrote:
> 
> I meet such a condition when configure log4j using an extended
> PropertyConfigurator.
> There are more than two dozens of Appenders use one same layout.
> What I did is just copy and paste them. However, everytime I make
> changes to the layout, I need to copy and paste again.
> 
> Can we configure layout in the similar way as for appenders ? We may
> define  a layout first and let appenders to make reference to that
> layout, just like we define an appender first and let categories to
> reference it.
> 
> It seems need to change the current log4j source.
> 
> Or any work around for the condition I meet?
> 
> Any responses are appreciated.
> 
> Jin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

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


Mime
View raw message