在Log4j2中扩展PatternLayout [英] Extend PatternLayout in Log4j2
问题描述
由于Log4J2的 org.apache.logging.log4j.core.layout.PatternLayout
Class是 final
,我可以不会扩展它以为我的 CSV 创建标题。
Since Log4J2's org.apache.logging.log4j.core.layout.PatternLayout
Class is final
, I can't extend it to create headers for my CSV.
我引用了文档,它没有提供有关如何扩展现有布局的信息。
http://logging.apache.org/log4j /2.x/manual/extending.html#Layouts
I referred docs, it doesn't provide info on how to extend existing Layout. http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
扩展PatternLayout的先前方法不起作用。
Previous approach of extending PatternLayout doesn't work.
我的目标是将标题添加到日志文件&标题应该通过以下日志的配置文件进行配置,
My goal is to add header to log file & headers should be configured through configuration file for below log,
<File name="MttPerformance" fileName="logs\MyLog.csv" append="true">
<PatternLayout pattern="%d{dd MMM yyyy},%d{HH:mm:ss,SSS},%m%n"/>
</File>
推荐答案
<PatternLayout pattern="%d{dd MMM yyyy},%d{HH:mm:ss,SSS},%m%n" header="Date,Time,Inf,Time(ms)${sys:line.separator}"/>
Log4j2有标头标签..!
https://logging.apache.org/log4j/2 .x / manual / layouts.html
Log4j2 has header tag..! https://logging.apache.org/log4j/2.x/manual/layouts.html
这篇关于在Log4j2中扩展PatternLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!