How to use java code to configure logback and set the log level?
•
Java
I want to use the default slf4j logback configuration, except for org springframework. data. document. The logging level of mongodb is set to debug
How do I use java code?
I didn't use XML, and this decision was made at run time
Solution
The following works for me, but generally speaking, it's not a good idea Your code will depend on logback (you cannot select another log frame after slf4j)
final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("test.package"); if (!(logger instanceof ch.qos.logback.classic.Logger)) { return; } ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger; logbackLogger.setLevel(ch.qos.logback.classic.Level.TRACE); logger.trace("some log");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码