mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '2.1.x'
This commit is contained in:
commit
6164e3efe8
@ -16,14 +16,19 @@
|
|||||||
|
|
||||||
package org.springframework.boot.context.logging;
|
package org.springframework.boot.context.logging;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||||
|
import org.springframework.boot.logging.LogFile;
|
||||||
import org.springframework.boot.logging.LoggingSystem;
|
import org.springframework.boot.logging.LoggingSystem;
|
||||||
import org.springframework.boot.testsupport.system.CapturedOutput;
|
import org.springframework.boot.testsupport.system.CapturedOutput;
|
||||||
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
||||||
@ -50,6 +55,17 @@ class LoggingApplicationListenerIntegrationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void logFileRegisteredInTheContextWhenApplicable(@TempDir File tempDir) throws Exception {
|
||||||
|
String logFile = new File(tempDir, "test.log").getAbsolutePath();
|
||||||
|
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class)
|
||||||
|
.web(WebApplicationType.NONE).properties("logging.file=" + logFile).run()) {
|
||||||
|
SampleService service = context.getBean(SampleService.class);
|
||||||
|
assertThat(service.logFile).isNotNull();
|
||||||
|
assertThat(service.logFile.toString()).isEqualTo(logFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput capturedOutput) {
|
void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput capturedOutput) {
|
||||||
new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).child(Config.class)
|
new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).child(Config.class)
|
||||||
@ -71,8 +87,11 @@ class LoggingApplicationListenerIntegrationTests {
|
|||||||
|
|
||||||
private final LoggingSystem loggingSystem;
|
private final LoggingSystem loggingSystem;
|
||||||
|
|
||||||
SampleService(LoggingSystem loggingSystem) {
|
private final LogFile logFile;
|
||||||
|
|
||||||
|
SampleService(LoggingSystem loggingSystem, ObjectProvider<LogFile> logFile) {
|
||||||
this.loggingSystem = loggingSystem;
|
this.loggingSystem = loggingSystem;
|
||||||
|
this.logFile = logFile.getIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,6 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
|
|||||||
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
|
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void logfileWithRandomName() {
|
|
||||||
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
|
|
||||||
.getForEntity("/admin/logfile", String.class);
|
|
||||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPassword() {
|
private String getPassword() {
|
||||||
return "password";
|
return "password";
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
server.error.path: /oops
|
server.error.path:/oops
|
||||||
management.endpoint.health.show-details: always
|
management.endpoint.health.show-details:always
|
||||||
management.endpoints.web.base-path: /admin
|
management.endpoints.web.base-path:/admin
|
||||||
logging.file=./target/${spring.application.instance_id}.log
|
|
||||||
spring.application.instance_id=${random.value}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user