views:

322

answers:

1

Is there a way to configure a log4j.xml file to have multiple appenders share the same layout? I have copied the layout parameter into each of the appenders but it's a pain (and seems weird that I would need to do this) to update it in multiple places if the pattern changes.

thanks, Jeff

+2  A: 

Have you considered using log4j.properties instead of log4j.xml? The properties version accepts variable substitution for the values.

You can create your own properties inside the log4j.properties file (someProp=value) and later use ${someProp} to get the value.

From what I remember (not sure though :D) you can also have this in the log4j.xml file but the variables must be defined as system variables (-DsomeProp=value) and in your log4j.xml you again use ${someProp}. This version though is a little messy because you do not have the params declared in the same place you are using them, as you do in log4j.properties.

dpb
I'll give it a shot with log4j.properties. I think you're right that it does support the properties but for some reason I like the xml format better. Thanks.
Jeff Storey