Skip to content

Allow changes to org.springframework.web log category at runtime #28477

Closed
@edwardsre

Description

@edwardsre

In a Spring Boot application using the spring-boot-starter-actuator loggers endpoint, setting the web log group, or any of it's individual member loggers, to debug level doesn't have any effect for RestTemplate logging.

We would like to be able to use the loggers endpoint to change the web log group logger levels on a deployed application in order to see web related debug logging.

It appears HttpAccessor is using an org.springframework.core.log.CompositeLog which initializes at application startup to current log levels, so adjusting the log levels through the actuator loggers endpoint doesn't have the desired effect.

Steps to duplicate:

Create a Spring Boot application using spring-initializr with spring-boot-starter-web and spring-boot-starter-actuator.
I am using Spring Boot 2.6.7

In application.properties, set:

logging.level.web=debug

Application code

@SpringBootApplication
@RestController
public class DemoApplication {

  private final RestTemplate restTemplate;

  public DemoApplication(RestTemplateBuilder builder) {
    this.restTemplate = builder.build();
  }

  @GetMapping
  public String doSomething() {
    return restTemplate.getForEntity("https://httpbin.org/get", String.class).getBody();
  }

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }

}

Startup the application and execute:

curl --location --request GET 'localhost:8080/'

You should see the [RestTemplate] related logging in the application console.

Now comment out the logger line in application.properties and restart the application.

Now set the logger level after application startup using the actuators endpoint

curl --location --request POST 'http://localhost:8080/actuator/loggers/web' \
--header 'Content-Type: application/json' \
--data-raw '{
  "configuredLevel": "DEBUG"
}'

Call the endpoint again

curl --location --request GET 'localhost:8080/'

Outcome

No [RestTemplate] related logging occurs.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions