我创建了一个 SpringBoot 管理服务器,客户端注册到它。我希望能够在运行时在 SpringBoot 管理服务器的“日志记录”选项卡中更改日志记录级别。在其中一个客户端中,我的问题是为“ke.co.betatech”包中的所有记录器创建一个父记录器,我将在运行时更改 Logger.getLogger("ke.co.betatech") 的日志记录级别,并且后代的日志记录级别更改。我不想使用根记录器来更改日志记录级别,因为它会更改所有已注册记录器的日志记录级别。
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"
}
}
在主要课程中,这是我尝试的
@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);
}
}
问题是,记录器Logger.getLogger("ke.co.betatech")
没有出现在 Spring Boot 管理服务器的记录器列表中。