Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
edwardsre opened this issue May 18, 2022 · 2 comments
Closed

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

edwardsre opened this issue May 18, 2022 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@edwardsre
Copy link

edwardsre commented May 18, 2022

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 18, 2022
@philwebb philwebb transferred this issue from spring-projects/spring-boot May 18, 2022
@philwebb
Copy link
Member

I've transferred this issue to the framework team since I think changes will be needed to CompositeLog to account for the fact that a Log instance be reconfigured (regardless of if it's by Spring Boot or something else).

@philwebb
Copy link
Member

I think we'll need to do something like this. We should also add some tests.

@rstoyanchev rstoyanchev self-assigned this May 20, 2022
@rstoyanchev rstoyanchev added this to the 5.3.21 milestone May 20, 2022
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 20, 2022
@rstoyanchev rstoyanchev changed the title Setting web log group level using actuator loggers endpoint has no effect for RestTemplate Allow chSetting web log group level using actuator loggers endpoint has no effect for RestTemplate May 20, 2022
@rstoyanchev rstoyanchev changed the title Allow chSetting web log group level using actuator loggers endpoint has no effect for RestTemplate Allow changes to org.springframework.web log category at runtime May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants