[英]adding microsecond level to log4j
How can I add microsecond level logging, how to create custom pattern formatter for this? 如何添加微秒级日志记录,如何为此创建自定义模式格式化程序?
I have also tried log4j2, but it ends up giving 我也尝试过log4j2,但最终却给了
12:42:05,972803200 [main] DEBUG Log4j2Test - Debug Message Logged !!!
12:42:05,975803200 [main] INFO Log4j2Test - Info Message Logged !!!
12:42:05,975803200 [main] ERROR Log4j2Test - Error Message Logged !!!
as you can see it gives 803200 microseconds and nanoseconds always. 如您所见,它始终提供803200微秒和纳秒的时间。
My log4j2.xml looks like: 我的log4j2.xml看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ABSOLUTE_NANOS} [%t] %-5level %logger{36} - %msg%n"/>
<!-- <PatternLayout
pattern="[%-5level] %d{ABSOLUTE_NANOS} [%t] %c{1} - %msg%n" /> -->
</Console>
</Appenders>
<Loggers>
<Root level="debug" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
It depends on what log4j you happen to be using. 这取决于您碰巧使用的是log4j。 This feature is only supported if you use JDK9 and new(er) version of log4j ( 2.x). 如果你使用JDK9和log4j的(2.X)新(ER)版本,此功能仅支持。
The format you happen to be searching for is this one: %d{HH:mm:ss,nnnnnn} 你碰巧被搜索的格式是这一个:%d {HH:MM:SS,NNNNNN}
Please also notice what official documentation says, because there are lots of "catches and gotchas". 也请注意什么官方文件说,因为有很多“渔获物和陷阱”的。 Ie: 即:
Log4j 2.11 adds limited support for timestamps more precise than milliseconds when running on Java 9. Note that not all DateTimeFormatter formats are supported. Log4j的2.11爪哇9.注意运行,并不是所有的DateTimeFormatter格式的支持时,增加了对时间戳比毫秒更精确的有限的支持。 Only timestamps in the formats mentioned in the table above may use the "nano-of-second" pattern letter n instead of the "fraction-of-second" pattern letter S. Users may revert back to a millisecond-precision clock when running on Java 9 by setting system property log4j2.Clock to SystemMillisClock 仅上表中提到的格式的时间戳可以使用“ nano-of-second”模式字母n代替“ second-fraction-of-second”模式字母S。用户在运行时可以恢复到毫秒级时钟Java的9由系统属性log4j2.Clock设置为SystemMillisClock
More info on following link: Log4j 2.x layouts 以下链接更多信息: Log4j的2.X布局
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.