在 simplelogger.properties 文件中,我们可以将默认日志记录级别设置为
org.slf4j.simpleLogger.defaultLogLevel=error
但是如果想为特定包设置日志记录级别那么该怎么做呢? 例如如果包名是
com.xxx.yyy
然后如果我把它放在 simplelogger.properties 中
com.xxx.yyy.level=error
那就不行了。 如何配置?
最佳答案
SLF4J SimpleLogger 拥有所有 its documentation in its Javadoc .
正如它所说,
org.slf4j.simpleLogger.log.a.b.c
- Logging detail level for a SimpleLogger instance named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent logger will be used, and if none is set, then the value specified byorg.slf4j.simpleLogger.defaultLogLevel
will be used.
所以你需要在你的 simplelogger.properties 中包含这样一行:
org.slf4j.simpleLogger.log.com.xxx.yyy=error
如果您开始需要比 SLF4J SimpleLogger 更复杂的日志记录系统,那么您可能想要切换到使用 Log4j 或 Logback 之类的东西。
关于java - 如何在 SLF4J-simple 的 simplelogger.properties 中为不同的包设置日志记录级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50677309/