开发者

Can I specify a Layout by reference in log4j configuration?

开发者 https://www.devze.com 2023-03-06 07:46 出处:网络
We can create appender-ref tags to specify an appender by refere开发者_开发问答nce.Is there something similar for Layouts?

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).

0

精彩评论

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