在输出中显示 FINE 日志级别

发布于 2024-09-16 04:56:40 字数 33 浏览 1 评论 0原文

我怎样才能在java的输出屏幕中显示精细的日志消息?

how can i display the fine log message in output screen in java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧 2024-09-23 04:56:40

您可能希望使用属性文件配置其他默认值。这允许重新配置而不需要重新编译。

# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

# Set the default logging level for the root logger
.level = ALL

# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = INFO

# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = ALL

# Set the default formatter for new ConsoleHandler instances
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Set the default logging level for the logger named com.mycompany
com.mycompany.level = ALL

我更喜欢这样做,而不是用日志配置调用来乱扔我的代码。

不过,您必须使用命令行选项指定文件的位置:

java -Djava.util.logging.config.file=mylogging.properties 

我个人总是使用 log4j 或 slf4j,因为它在类路径中查找配置文件。好吧,也许 java.util.logging 也这样做,我从未真正调查过。

You might want to configure other defaults with a properties file. This allow things to be reconfigured without recompiling.

# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

# Set the default logging level for the root logger
.level = ALL

# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = INFO

# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = ALL

# Set the default formatter for new ConsoleHandler instances
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Set the default logging level for the logger named com.mycompany
com.mycompany.level = ALL

I prefer this to littering my code with logging configuration calls.

You have to specify the location of the file with a command line option though :

java -Djava.util.logging.config.file=mylogging.properties 

I personally always use log4j or slf4j because it looks for a config file in the classpath. Well, maybe java.util.logging does that too, I never really investigated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文