Extend PatternLayout in Log4j2

微笑、不失礼 提交于 2019-12-07 21:11:03

问题


Since Log4J2's org.apache.logging.log4j.core.layout.PatternLayout Class is final, I can't extend it to create headers for my CSV.

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

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>

回答1:


<PatternLayout pattern="%d{dd MMM yyyy},%d{HH:mm:ss,SSS},%m%n" header="Date,Time,Inf,Time(ms)${sys:line.separator}"/>

Log4j2 has header tag..! https://logging.apache.org/log4j/2.x/manual/layouts.html



来源:https://stackoverflow.com/questions/31739739/extend-patternlayout-in-log4j2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!