如何将日期时间戳添加到log4j2日志文件? [英] How to add the date timestamp to log4j2 logfiles?

查看:152
本文介绍了如何将日期时间戳添加到log4j2日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 log4j2 创建日依赖日志文件:

I want to create day dependent logfiles with log4j2:

<RollingFile name="APP" fileName="application-%d{yyyy-MM-dd}.log" />

结果日志文件名: application-%d {yyyy-MM-dd} .log ,时间戳未被替换。为什么?

Resulting logfile name: application-%d{yyyy-MM-dd}.log, the timestamp is not replaced. Why?

推荐答案

不应在属性fileName中给出模式,而是必须在属性中指定模式 filePattern如下所示。

The pattern should not be given in the attribute "fileName" rather you have to specify the pattern in the attribute "filePattern" as like below.

<RollingFile name="RollingFile" fileName="${log-path}/filename.log" 
filePattern="${log-path}/filename-%d{yyyy-MM-dd}-%i.log" >
...
...
</RollingFile>

%i是将在翻转时自动递增的计数器。

The "%i" is the counter that will be automatically incremented in rollover.

希望这会对你有帮助。

这篇关于如何将日期时间戳添加到log4j2日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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