Search code examples
javaspringloggingspring-bootspring-boot-admin

SpringBoot Admin and logging


I have created a SpringBoot Admin Server where clients register to it. I wish to be able to change logging levels at runtime in the 'Logging' tab in the SpringBoot Admin Server. In one of the clients, my problem is creating a parent logger for all loggers in the package "ke.co.betatech" where I would change the logging level for Logger.getLogger("ke.co.betatech") at runtime and the descendant's logging level changes. I don't want to use the root logger to change the logging level since it changes the logging levels for all loggers registered.

package ke.co.betatech.controllers;

@RestController
@RequestMapping("/api/v1")
public class Controller2 implements IController {

  Logger LOG;

  public Controller2() {
     LOG = Logger.getLogger(this.getClass());
  }

  @GetMapping("/greeting")
  public String hello() {
    LOG.info("Hello");
    return "hello"
  }
}

In the main class this is what I attempted

@SpringBootApplication
public class LoggingLevelRuntimeApplication {

   public static void main(String[] args) {
      // I created the parent logger here
      Logger log = Logger.getLogger("ke.co.betatech");
      SpringApplication.run(LoggingLevelRuntimeApplication.class, args);
   }
}

The problem is, the logger Logger.getLogger("ke.co.betatech") does not appear in the list of loggers in the Spring Boot Admin Server.


Solution

  • You can show the package loggers if you click on the symbol right next to the search input on the logging page.

    enter image description here