我正在尝试在 slf4j 过滤器内使用 java.util.logging,因为我无法在那里使用 slf4j 记录器。
我正在使用 Java 11 并使用 Maven 进行构建。
由于某种原因,我可以在我的日志(控制台)中显示 SEVERE、INFO 和 WARNING 日志,但不能显示 FINE。我正在使用命令行上的系统属性或在“logging.properties”文件中将日志级别设置为“FINER”。
为了简单起见,我只是创建这个记录器:
private static Logger logger = Logger.getLogger("abc");
我用以下内容创建了“src/main/resources/logging.properties”:
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
abc.level=FINER
在执行的方法中,我有这个:
logger.log(Level.FINE, "Loading security filter config file: " + fileName + " with override contents: " + overrideContents);
logger.log(Level.SEVERE, "This is a test.");
logger.severe("This is a test.");
logger.config("This is a test.");
logger.info("This is a test.");
logger.warning("This is a test.");
logger.fine("Loading security filter config file: " + fileName + " with override contents: " + overrideContents);
这是我在控制台日志中看到的内容:
Apr 26, 2024 3:45:36 PM com.att.idp.logging.provider.filter.SecurityFilter loadSecurityFilterConfig
SEVERE: This is a test.
Apr 26, 2024 3:45:54 PM com.att.idp.logging.provider.filter.SecurityFilter loadSecurityFilterConfig
SEVERE: This is a test.
Apr 26, 2024 3:45:54 PM com.att.idp.logging.provider.filter.SecurityFilter loadSecurityFilterConfig
INFO: This is a test.
Apr 26, 2024 3:45:54 PM com.att.idp.logging.provider.filter.SecurityFilter loadSecurityFilterConfig
WARNING: This is a test.
它不会发出任何 FINE 级别日志。
我还能展示哪些有用的内容?
ConsoleHandler
的级别:
java.util.logging.ConsoleHandler.level = FINER
配置文件logging.properties默认位于您的JDK/JRE文件夹中。直到您使用自定义文件覆盖它。