gpt4 book ai didi

java - 在输出中显示 FINE 日志级别

转载 作者:太空宇宙 更新时间:2023-11-04 08:50:02 25 4
gpt4 key购买 nike

如何在 java 的输出屏幕中显示精细日志消息?

最佳答案

您可能希望使用属性文件配置其他默认值。这允许在不重新编译的情况下重新配置事物。

# 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 也这样做,我从未真正调查过。

关于java - 在输出中显示 FINE 日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3553927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com