Dropwizard管理员:更改所有的loglevel

问题描述:

我的配置是标准的

logging:

  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO

  # Logger-specific levels.
  loggers:

    # Sets the level for 'com.example.app' to DEBUG.
    com.example.app: DEBUG

    # Redirects SQL logs to a separate file
    org.hibernate.SQL:
      level: DEBUG

我想将所有记录器的默认日志级别更改为 DEBUG 。我已经尝试了以下内容并且没有任何效果(比如管理端口是1234):

I want to change the default log level for all loggers to DEBUG. I've tried the following and nothing works (say admin port is 1234):

curl -X POST -d "logger=all&level=DEBUG" localhost:1234/tasks/log-level
curl -X POST -d "level=DEBUG" localhost:1234/tasks/log-level
curl -X POST -d "logger=*&level=DEBUG" localhost:1234/tasks/log-level

当我跑步时这些使用 -vv ,例如对于 logger = all ,我看到已配置的日志记录级别all to DEBUG ,但拖尾日志不会改变,仍然是INFO。当然,如果我更改配置并将*设置为 DEBUG ,并重新启动,我将获得DEBUG级别。

When I run these with -vv, for example for logger=all, I see Configured logging level for all to DEBUG, but the tailing the log does not change, and is still INFO. Of course, if I change the config and set the top level to DEBUG, and restart, I get DEBUG level.

命令是什么?

检查源代码对于日志级别任务,其主要逻辑实现如下:

I've checked the source code for the log-level task and its main logic is implemented like this:

for (String loggerName : loggerNames) {
    ((LoggerContext) loggerContext).getLogger(loggerName).setLevel(loggerLevel);
    output.println(String.format("Configured logging level for %s to %s", loggerName, loggerLevel));
    output.flush();
}

所以它的实现方式是基于记录器的名称,知道这个我进入 org.slf4j.Logger 界面的源代码,找到了这个字段:

So the way it's implemented is based on the name for the logger, knowing this I went into the source for org.slf4j.Logger interface and found this field:

String ROOT_LOGGER_NAME = "ROOT";

执行 POST 这样解决了我:

curl -X POST -d "logger=ROOT&level=DEBUG" localhost:8081/tasks/log-level