log4j:以毫秒为单位的当前时间 [英] log4j : current time in milliseconds

查看:1655
本文介绍了log4j:以毫秒为单位的当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

log4j.properties 我可以设置 PatternLayout 例如([%p]%c - %m - %d%n)

是否有任何符号(%something)以毫秒为单位返回当前时间?

Is there any symbol (%something) which returns current time in milliseconds?

推荐答案

没有Log4J符号完全符合您的要求。

There is no Log4J symbol that does exactly what you want.

%d 返回给定模式的当前日期,由 SimpleDateFormat (你在括号之间放置的模式),但没有给你时间毫秒。

%d returns the current date with a given pattern, defined by a SimpleDateFormat (the pattern you put between the brackets), but doesn't give you the time in millis.

%r 给出自执行开始以来的毫秒数

%r gives the number of milliseconds since the start of execution.

实现目标的一种可能方法是扩展Log4j的行为,它有点复杂,但如果它绝对必要......在这里你去:

One possible way of achieving what you want is to extend the behaviour of Log4j, it's quite a bit more complex, but if it's absolutely necessary... here you go:

自定义log4j (编辑:不再在线?)

自定义log4j (编辑:2018替代)

Customize log4j (edit: no longer online?)
Customize log4j (edit: 2018 alternative)

编辑
Keep请记住,根据您的评论,如果您需要确定不同机器中执行之间的时间差异,您必须确保机器的时钟同步,否则它将导致您得出错误的结论。

Edit: Keep in mind that, from your comment, if you need to figure out time differences between executions in different machines, you have to make sure the clocks of the machines are synchronized, or it'll be leading you to wrong conclusions.

这篇关于log4j:以毫秒为单位的当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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