如何在log4j2中产生标题行 [英] How to produce a header row in log4j2

查看:76
本文介绍了如何在log4j2中产生标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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中产生标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆