SLF4J+Logback 查看加载顺序

– Start

package demo04;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;

public class App {
	// 创建 logger 对象
	final static Logger logger = LoggerFactory.getLogger(App.class);

	public static void main(String[] args) {
		// 打印内部信息
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		StatusPrinter.print(lc);
		
		// 日志分为5种级别,从低到高依次为下面
		logger.trace("trace");
		logger.debug("debug");
		logger.info("info");
		logger.warn("warn");
		logger.error("error");
	}

}

输出结果如下。

20:54:55,666 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
20:54:55,667 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
20:54:55,667 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
20:54:55,673 |-INFO in ch.qos.logback.classic.BasicConfigurator@7e6cbb7a - Setting up default configuration.

20:54:55.733 [main] DEBUG demo04.App - debug
20:54:55.736 [main] INFO demo04.App - info
20:54:55.736 [main] WARN demo04.App - warn
20:54:55.736 [main] ERROR demo04.App - error

从上面的结果中我们可以看到。

  1. Logback 首先加载配置文件logback-test.xml
  2. 如果没找到,就加载 logback.groovy
  3. 如果还没找到,就加载 logback.xml
  4. 如果还没找到,就使用默认配置。

– 更多参见:SLF4J+Logback 精萃
– 声 明:转载请注明出处
– Last Updated on 2019-08-22
– Written by ShangBo on 2019-08-22
– End

你可能感兴趣的:(Logback)