0

我创建了一个 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 管理服务器的记录器列表中。

4

2 回答 2

1

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

在此处输入图像描述

于 2016-11-21T21:30:19.087 回答
0

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

于 2016-11-21T14:43:20.760 回答