如何配置jdk14日志记录的模式

编程入门 行业动态 更新时间:2024-10-26 06:29:25
本文介绍了如何配置jdk14日志记录的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想我可以通过添加行java.util.logging.ConsoleHandler.pattern来编辑模式,但是在哪里检查模式信息,如%u%h等?

AFAIK没有这样的财产。有一个 java.util.logging.FileHandler.pattern ,但这是设置输出文件名的模式,而不是日志格式。

在util日志API中配置输出格式的方法是设置 Formatter 。默认情况下, SimpleFormatter 附加到 ConsoleHandler 。此格式化程序只是对模式进行硬编码,并且不允许您进行设置。

如果您需要不同的输出格式,则必须实现自己的 Formatter ,或使用不同的日志框架,例如 logback 。

I guess I can chnage pattern by adding the line java.util.logging.ConsoleHandler.pattern, however where to check the pattern information like %u %h etc?

解决方案

Edit: The below was written at the time for Java 6. For 7 and later, refer to David's answer below.

AFAIK there is no such property. There is a java.util.logging.FileHandler.pattern but this is to set the pattern of the output filename, not of the logging format.

The way you configure the output format in the util logging API is by setting the Formatter. By default, a SimpleFormatter is attached to your ConsoleHandler. This formatter simply hardcodes the pattern and doesn't allow you to set it.

If you need a different output format, you'll have to either implement your own Formatter, or use a different logging framework, such as logback.

更多推荐

如何配置jdk14日志记录的模式

本文发布于:2023-11-07 14:52:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!