We can create appender-ref
tags to specify an appender by refere开发者_开发问答nce. Is there something similar for Layouts?
For example:
// ...
<layout name="MYLAYOUT" class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d][%t][%c][%M][%p]: %m%n"/>
</layout>
<root>
<appender-ref ref="CONSOLE"/>
<layout-ref ref="MYLAYOUT"/>
</root>
Unfortunately, this is impossible out of the box.
You could, however, write your own layout class, e.g. as a subclass of PatternLayout
.
Your custom layout could then feature a parameter ConversionPattern-ref
, or it could be implemented in such a way that all instances use the pattern that was last set (instead of reverting to a default).
精彩评论