Log file location should be evaluated just once

Using a random value for the logfile name caused
the logfile endpoint to return a 404 as the name
was resolved from the environment on every request.
This commit registers a bean for LogFile which is then
used by the logfile endpoint.

Fixes gh-17434
This commit is contained in:
Madhura Bhave
2019-07-08 15:32:19 -07:00
parent 7854876608
commit 773dda3d55
8 changed files with 55 additions and 48 deletions

View File

@@ -66,6 +66,13 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
}
@Test
public void logfileWithRandomName() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
.getForEntity("/admin/logfile", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
private String getPassword() {
return "password";
}

View File

@@ -1,3 +1,5 @@
server.error.path: /oops
management.endpoint.health.show-details: always
management.endpoints.web.base-path: /admin
logging.file=./target/${spring.application.instance_id}.log
spring.application.instance_id=${random.value}