diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java index 13ee7da70bd..c86e3401f6d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java @@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.core.HelpCommand; import org.springframework.boot.cli.command.core.HintCommand; import org.springframework.boot.cli.command.core.VersionCommand; import org.springframework.boot.cli.command.shell.ShellCommand; +import org.springframework.boot.loader.tools.LogbackInitializer; /** * Spring Command Line Interface. This is the main entry-point for the Spring command line @@ -37,6 +38,7 @@ public class SpringCli { public static void main(String... args) { System.setProperty("java.awt.headless", Boolean.toString(true)); + LogbackInitializer.initialize(); CommandRunner runner = new CommandRunner("spring"); runner.addCommand(new HelpCommand(runner)); diff --git a/spring-boot-tools/spring-boot-loader-tools/pom.xml b/spring-boot-tools/spring-boot-loader-tools/pom.xml index d1fb124c68f..3a774fe0396 100644 --- a/spring-boot-tools/spring-boot-loader-tools/pom.xml +++ b/spring-boot-tools/spring-boot-loader-tools/pom.xml @@ -29,6 +29,11 @@ spring-boot-loader provided + + ch.qos.logback + logback-classic + provided + org.zeroturnaround diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java new file mode 100644 index 00000000000..b8211270857 --- /dev/null +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LogbackInitializer.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.loader.tools; + +import org.slf4j.ILoggerFactory; +import org.slf4j.Logger; +import org.slf4j.impl.StaticLoggerBinder; +import org.springframework.util.ClassUtils; + +import ch.qos.logback.classic.Level; + +/** + * @author Dave Syer + */ +public class LogbackInitializer { + + public static void initialize() { + if (ClassUtils.isPresent("org.slf4j.impl.StaticLoggerBinder", null)) { + new Initializer().setRootLogLevel(); + } + } + + private static class Initializer { + public void setRootLogLevel() { + ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory(); + Logger logger = factory.getLogger(Logger.ROOT_LOGGER_NAME); + ((ch.qos.logback.classic.Logger) logger).setLevel(Level.INFO); + } + } +}