0

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.

4

2 に答える 2

0

ファイルに追加logging.level.ke.co.betatech=DEBUGすると、完了後に一度任意のクラスでapplication.propertiesロガーを使用できるようになります 。Logger log = Logger.getLogger("ke.co.betatech");SpringApplication.run()

于 2016-11-21T14:43:20.760 に答える