如何让 java 日志输出显示在一行上? [英] How do I get java logging output to appear on a single line?
本文介绍了如何让 java 日志输出显示在一行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前默认条目看起来像这样:
At the moment a default entry looks something like this:
Oct 12, 2008 9:45:18 AM myClassInfoHere
INFO: MyLogMessageHere
我如何让它做到这一点?
How do I get it to do this?
Oct 12, 2008 9:45:18 AM myClassInfoHere - INFO: MyLogMessageHere
澄清我正在使用 java.util.logging
Clarification I'm using java.util.logging
推荐答案
从 Java 7 开始,java.util.logging.SimpleFormatter 支持获取它的 format 来自系统属性,因此将这样的内容添加到 JVM 命令行将导致它一行打印:
As of Java 7, java.util.logging.SimpleFormatter supports getting its format from a system property, so adding something like this to the JVM command line will cause it to print on one line:
-Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
或者,您也可以将其添加到您的 logger.properties
:
Alternatively, you can also add this to your logger.properties
:
java.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
这篇关于如何让 java 日志输出显示在一行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文