[问题记录] spring-boot 打印启动时间

来源:互联网 发布:女装知茵品牌 编辑:程序博客网 时间:2024/05/18 12:40

问题
spring-boot 工程启动结束会打印启动时间
Started Application in 12.805 seconds (JVM running for 20.686)

最近新建一个工程发现启动完后并没有打印上面的那句话

解决

查看源码,发现打印日志在

public ConfigurableApplicationContext run(String... args) {        StopWatch stopWatch = new StopWatch();        stopWatch.start();        ConfigurableApplicationContext context = null;        FailureAnalyzers analyzers = null;        configureHeadlessProperty();        SpringApplicationRunListeners listeners = getRunListeners(args);        listeners.starting();        try {            ApplicationArguments applicationArguments = new DefaultApplicationArguments(                    args);            ConfigurableEnvironment environment = prepareEnvironment(listeners,                    applicationArguments);            Banner printedBanner = printBanner(environment);            context = createApplicationContext();            analyzers = new FailureAnalyzers(context);            prepareContext(context, environment, listeners, applicationArguments,printedBanner);            //著名的refresh             refreshContext(context);            afterRefresh(context, applicationArguments);            listeners.finished(context, null);            stopWatch.stop();            //打印启动时间日志            if (this.logStartupInfo) {                new StartupInfoLogger(this.mainApplicationClass)                        .logStarted(getApplicationLog(), stopWatch);            }            return context;        }        catch (Throwable ex) {            handleRunFailure(context, listeners, analyzers, ex);            throw new IllegalStateException(ex);        }    }
public void logStarted(Log log, StopWatch stopWatch) {        if (log.isInfoEnabled()) {            log.info(getStartedMessage(stopWatch));        }    }

其打印是的info级日志,而我在logback配置启动类Application包的别类是WARN级别的,所以它并不打印时间,把启动类Application所在包日志级别改为info即可。

原创粉丝点击