如何在log4j2中产生标题行

编程入门 行业动态 更新时间:2024-10-19 23:32:07
本文介绍了如何在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中产生标题行

本文发布于:2023-11-02 17:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!