– Start
指定配置文件地址。
package demo06;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.util.StatusPrinter;
public class App {
static {
// 通过命令行参数指定配置文件的地址
// java -Dlogback.configurationFile=demo05/logback.xml
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, "demo06/logback.xml");
}
// 创建 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");
}
}
– 更多参见:SLF4J+Logback 精萃
– 声 明:转载请注明出处
– Last Updated on 2019-08-24
– Written by ShangBo on 2019-08-24
– End