Commit 894482df authored by Dave Syer's avatar Dave Syer

Initialize logback is it is present in CLI

This (empirically) fixes gh-726 using a new utility
(LogbackInitializer) in the loader tools. If anyone has enough
Gradle fu to understand where to put it (after the classpath is established
but before compilation) we could do the same thing in the Gradle plugin
(and that would fix gh-724).
parent 1ef3d3bd
......@@ -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));
......
......@@ -29,6 +29,11 @@
<artifactId>spring-boot-loader</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.zeroturnaround</groupId>
......
/*
* 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);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment