在log4j中,有时我们创建第二个记录器,并向其输出CSV数据,作为对应用程序的指标监视.与我们用于调试之类的普通日志相反,该数据易于导入和绘制图形.
In log4j, we sometimes create a second logger and output CSV data to it as sort of a metrics watch of the application. This data is easily imported and graphed, as opposed to the normal log which we use for debugging and the like.
在旧的log4j中,我们通过将PatternLayout子类化,覆盖header属性并将其指定为:
In old log4j we did this by subclassing the PatternLayout, overriding the header property, and specifying it as:
log4j.logger.servicePerformance=INFO, servicePerformance log4j.appender.servicePerformance=mypackage.log4j.SingleHeaderFileAppender log4j.appender.servicePerformance.File=logs/performance.log log4j.appender.servicePerformance.layout=mypackage.log4j.HeaderLayout log4j.appender.servicePerformance.layout.ConversionPattern=%m%n log4j.appender.servicePerformance.layout.Header=Start Time, Service Invoked, Elapsed ms, Candidate Count, Asset Count log4j.additivity.servicePerformance=false我不确定如何在log4j 2中执行此操作,现在我们已经有两个应用程序最近转换为可以使用.
I'm not sure how to do this in log4j 2 which we now have two applications recently converted to use.
推荐答案Log4j2的PatternLayout还支持页眉和页脚属性:
Log4j2's PatternLayout also supports the header and footer attributes:
<PatternLayout> <pattern>%d %p [%t] %c %m%n</pattern> <header>This is a header</header> <footer>(c) 1999-2014</footer> </PatternLayout>我认为属性也可以工作:
I think attributes work too:
<PatternLayout pattern="%d %p [%t] %c %m%n" header="This is a header" footer="(c) 1999-2014" />此文件未正确记录,感谢您指出这一点.
This is not documented correctly, thanks for pointing this out.
更多推荐
如何在log4j2中产生标题行
发布评论