Likewise, the Spring Boot actuator provides two valuable endpoints for log management. The first one is /actuator/loggers, which allows accessing and changing logging levels at runtime without the application restart. This endpoint is very helpful since switching the granularity of information without a service restart is an essential part of a successful application operation. In light of the complicated debug experience related to reactive applications, the ability to switch log levels and analyze the outcome on the fly is crucial. Of course, it is not very convenient to change log levels from a console with a curl command, but this feature plays well with Spring Boot admin, which provides a pretty UI for such purposes.
This feature makes it possible to enable or disable dynamically generated logs by a Reactor log() operator that was described in Chapter 4, Project Reactor - the Foundation for Reactive Apps. The following code depicts a reactive service that pushes events to the SSE stream:
@GetMapping(path = "/temperature-stream",
produces = MediaType.TEXTEVENTSTREAMVALUE)
public Flux<TemperatureDto> temperatureEvents() {
return temperatureSensor.temperatureStream()
.log("sse.temperature", Level.FINE) // (1)
.map(this::toDto);
}
Here, the log() operator registers a logger sse.temperature with a Level.FINE (1). Consequently, we may dynamically enable or disable the output for this logger using the /actuator/loggers endpoint.
On the other hand, an ability to access application logs without a need to copy files from a remote server might be advantageous. To simplify that, Spring Boot actuator provides an /actuator/logfile endpoint that exposes a file with logs over the web. Spring Boot admin also has a neat web page that streams application logs to a UI in a pretty convenient way.