mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Turn down logging
This commit is contained in:
parent
da07cdf41f
commit
132722100a
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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() {
|
||||
|
@ -34,4 +34,6 @@
|
||||
</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>
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user