Spring Boot 管理和日志记录

SpringBoot Admin and logging

我创建了一个 Spring引导管理服务器,客户端可以在其中注册。我希望能够在运行时在 Spring 启动管理服务器的 'Logging' 选项卡中更改日志记录级别。在其中一个客户端中,我的问题是为包 "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"
  }
}

主要class这就是我尝试的

@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 引导管理服务器的记录器列表中。

在您的 application.properties 文件中添加 logging.level.ke.co.betatech=DEBUG,您将能够使用记录器 Logger log = Logger.getLogger("ke.co.betatech"); 在任何 class 中一次 SpringApplication.run() 完成后。

如果您单击日志页面上搜索输入旁边的符号,您可以显示包记录器。