开发者

java log4j.xml multiple appenders sharing a layout

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 ne开发者_StackOverflow社区ed to do this) to update it in multiple places if the pattern changes.

thanks, Jeff


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜