slf4j使用jdk进行日志记录 - 如何启用调试? [英] slf4j logging with jdk – how to enable debug?

查看:250
本文介绍了slf4j使用jdk进行日志记录 - 如何启用调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,slf4j与jdk( slf4j-jdk14-1.6.1.jar )一起使用时,不会记录调试消息。
如何启用它们?

By default slf4j, when using with jdk (slf4j-jdk14-1.6.1.jar), does not log debug messages. How do I enable them?

我无法在官方文档,网络或此处找到有关如何启用它的信息。

I can’t find info neither in the official docs, the web or here on how to enable it.

我在%JDK_HOME%/ lib中创建了一个文件,但在配置文件中定义了那里的级别。
但是,我想在编译/运行时定义级别,以便我可以从具有不同日志记录级别的IDE运行和调试我的应用程序。

I found some info on (failed though) creating a file in %JDK_HOME%/lib and defining the level there, in a config file. However, I would like to define the level at compile-/run-time so I can both run and debug my app from my IDE with different logging levels.

我可以设置一些环境变量,还是VM arg?

Isn’t there some environment variable I can set, or VM arg?

推荐答案

为什么你认为它没有记录DEBUG消息?

Why do you think it does not log DEBUG messages?

如果你的意思是你的 log.debug(String)日志记录调用没有结束于 java.util.logging 日志文件,然后我想你必须配置 logging.properties 配置文件以允许日志消息在 FINE 级别。

If you mean that your log.debug(String) logging calls do not end up in java.util.logging log files, then I guess you have to configure the logging.properties configuration file to allow log messages at FINE level.

如果你不想搞乱全局%JRE_HOME %/ lib / logging.properties ,然后你可以传入 -Djava.util.logging.config.file = logging.properties 命令行 - 这将强制日志记录系统在当前目录中查找该配置文件。

If you do not want to mess with the global %JRE_HOME%/lib/logging.properties, then you can just pass in -Djava.util.logging.config.file=logging.properties on the command line - this will force the logging system to look for that configuration file in the current directory.

或使用其他(编程)方式配置 java.util.logging ,请参阅下面的教程。

Or use some other (programmatic) way to configure java.util.logging, see below for tutorial.

这与配置SLF4J无关;事实上,SLF4J没有任何配置,只需交换JAR文件即可配置

This has nothing to do with configuring SLF4J; in fact, SLF4J does not have any configuration, everything is configured by simply swapping JAR files.

供您参考:

  • JDK14LoggerAdapter
  • Java Logging API tutorial

这篇关于slf4j使用jdk进行日志记录 - 如何启用调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆