Turn down logging

This commit is contained in:
Phillip Webb 2013-07-24 16:58:04 -07:00
parent da07cdf41f
commit 132722100a
4 changed files with 27 additions and 16 deletions

View File

@ -347,8 +347,11 @@ public class SpringApplication {
}
protected void logStartupInfo() {
new StartupInfoLogger(this.mainApplicationClass).log(getApplicationLog());
getApplicationLog().info("Sources: " + this.sources);
Log applicationLog = getApplicationLog();
new StartupInfoLogger(this.mainApplicationClass).log(applicationLog);
if (applicationLog.isDebugEnabled()) {
applicationLog.debug("Sources: " + this.sources);
}
}
/**

View File

@ -46,6 +46,15 @@ class StartupInfoLogger {
public void log(Log log) {
Assert.notNull(log, "Log must not be null");
if (log.isInfoEnabled()) {
log.info(getStartupMessage());
}
if (log.isDebugEnabled()) {
log.debug(getRunningMessage());
}
}
private String getStartupMessage() {
StringBuilder message = new StringBuilder();
message.append("Starting ");
message.append(getApplicationName());
@ -53,13 +62,16 @@ class StartupInfoLogger {
message.append(getOn());
message.append(getPid());
message.append(getContext());
log.info(message);
message.setLength(0);
return message.toString();
}
private StringBuilder getRunningMessage() {
StringBuilder message = new StringBuilder();
message.append("Running with Spring Bootstrap");
message.append(getVersion(SpringApplication.class));
message.append(", Spring");
message.append(getVersion(ApplicationContext.class));
log.info(message);
return message;
}
private String getApplicationName() {

View File

@ -32,6 +32,8 @@
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
<logger name="org.hibernate.validator.internal.util.Version" level="WARN"/>
<logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN"/>
<logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN"/>
</configuration>

View File

@ -22,16 +22,18 @@ import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* Tests for {@link StartupInfoLogger}.
*
* @author Dave Syer
*/
public class StartUpLoggerInfoTests {
public class StartUpLoggerTests {
private StringBuffer output = new StringBuffer();
private SimpleLog log = new SimpleLog("test") {
@Override
protected void write(StringBuffer buffer) {
StartUpLoggerInfoTests.this.output.append(buffer).append("\n");
StartUpLoggerTests.this.output.append(buffer).append("\n");
};
};
@ -40,14 +42,6 @@ public class StartUpLoggerInfoTests {
new StartupInfoLogger(getClass()).log(this.log);
assertTrue("Wrong output: " + this.output,
this.output.toString().contains("Starting " + getClass().getSimpleName()));
// System.err.println(this.output);
}
@Test
public void bootstrapVersionIncluded() {
new StartupInfoLogger(getClass()).log(this.log);
assertTrue("Wrong output: " + this.output,
this.output.toString().contains("Spring Bootstrap v"));
}
}