Turn down logging

pull/9/head
Phillip Webb 11 years ago
parent da07cdf41f
commit 132722100a

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

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

@ -34,4 +34,6 @@
</root> </root>
<logger name="org.hibernate.validator.internal.util.Version" level="WARN"/> <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> </configuration>

@ -22,16 +22,18 @@ import org.junit.Test;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link StartupInfoLogger}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class StartUpLoggerInfoTests { public class StartUpLoggerTests {
private StringBuffer output = new StringBuffer(); private StringBuffer output = new StringBuffer();
private SimpleLog log = new SimpleLog("test") { private SimpleLog log = new SimpleLog("test") {
@Override @Override
protected void write(StringBuffer buffer) { 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); new StartupInfoLogger(getClass()).log(this.log);
assertTrue("Wrong output: " + this.output, assertTrue("Wrong output: " + this.output,
this.output.toString().contains("Starting " + getClass().getSimpleName())); 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"));
} }
} }
Loading…
Cancel
Save