如何从 2 行 java.util.logging 输出中隐藏日期行?
我正在使用Java默认记录器,现在它正在输出大量无用的垃圾,这是一个例子,这行代码:
log.info("Logging pointless information...")
将输出所有这些:
Oct 26, 2011 9:37:57 PM java.util.logging.LogManager$RootLogger log
INFO: Logging pointless information...
除了那一秒之外,我不需要知道任何事情线。我怎样才能清除这些垃圾?我想要的只是简单的文本记录。
I'm using the Java default logger, and right now it's printing a lot of useless trash to the output, here is a example, this line of code:
log.info("Logging pointless information...")
Will output all of this:
Oct 26, 2011 9:37:57 PM java.util.logging.LogManager$RootLogger log
INFO: Logging pointless information...
I don't need to know anything except that second line. How can I remove this trash? All I want is simple text logging.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这是后来添加的,但至少在 Java 7 中,java.util.logging.SimpleFormatter 支持从系统属性获取其格式。这个 JVM 参数将只打印第二行:
就个人而言,我喜欢保留所有日期/源信息,但去掉换行符(并使用更紧凑的国际日期格式):
Maybe this was added later, but at least with Java 7, java.util.logging.SimpleFormatter supports getting its format from a system property. This JVM argument will print just the second line:
Personally, I like to keep all the date/source info, but get rid of the newline (and use a more compact, international date format):
您需要创建一个不同的格式化程序并使用它。
You need to create a a different Formatter and use it instead.
这些都在问几乎相同的问题:
这是一个示例如何实施 Jarrod Roberson 的建议:http://www.javalobby.org/java/forums/t18515.html
一般来说,要应用格式化程序,您需要创建一个文件,通常称为logging.properties。在其中添加一行这样的内容:
或者无论您的格式化程序类是什么。然后添加一个像这样的 JVM 参数:
或者使用更强大的日志系统,例如 Logback 或 Log4j,它们具有预构建的格式化程序来节省您一些编码。
These are asking pretty much the same question:
Here's an example of how to implement Jarrod Roberson's suggestion: http://www.javalobby.org/java/forums/t18515.html
In general, to apply a formatter you create a file, usually called logging.properties. In it put a line like this:
or whatever your formatter class is. Then add a JVM arg like this:
Or use a more powerful logging system, like Logback or Log4j, which have prebuilt formatters to save you some coding.