如何在 simplelogger.properties 中为 SLF4J-simple 设置不同包的日志记录级别
How to set logging level for different packages in simplelogger.properties for SLF4J-simple
在simplelogger.properties文件中,我们可以将默认日志记录级别设置为
org.slf4j.simpleLogger.defaultLogLevel=error
但是如果想为特定包设置日志记录级别那么该怎么做呢?
例如如果包名称是
com.xxx.yyy
然后如果我把它放在simplelogger.properties中作为
com.xxx.yyy.level=error
那就不行了。
如何配置?
要在您自己的包上设置级别,请使用不同的文件per logging implementation
Configure SLF4J working with Java Logger
configure JDK logging either by editing JRE_DIRECTORY/lib/logging.properties
Configure SLF4J working with Log4J
add a configuration file such as src/main/resources/log4j.properties.
Configure SLF4J working with Logback
add a configuration file such as src/main/resources/logback.xml
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 by org.slf4j.simpleLogger.defaultLogLevel
will be used.
因此您需要在 simplelogger.properties:
中包含这样一行
org.slf4j.simpleLogger.log.com.xxx.yyy=error
如果您开始需要比 SLF4J SimpleLogger 更复杂的日志系统,那么您可能想要切换到使用 Log4j 或 Logback 之类的东西。
在simplelogger.properties文件中,我们可以将默认日志记录级别设置为
org.slf4j.simpleLogger.defaultLogLevel=error
但是如果想为特定包设置日志记录级别那么该怎么做呢? 例如如果包名称是
com.xxx.yyy
然后如果我把它放在simplelogger.properties中作为
com.xxx.yyy.level=error
那就不行了。 如何配置?
要在您自己的包上设置级别,请使用不同的文件per logging implementation
Configure SLF4J working with Java Logger
configure JDK logging either by editing JRE_DIRECTORY/lib/logging.properties
Configure SLF4J working with Log4J
add a configuration file such as src/main/resources/log4j.properties.
Configure SLF4J working with Logback
add a configuration file such as src/main/resources/logback.xml
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 之类的东西。