Dropwizard Admin: Change loglevel for all

孤者浪人 提交于 2020-01-11 03:33:13

问题


My config is the standard

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

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

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.

What's the command?


回答1:


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();
}

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";

Doing a POST like this solved it for me:

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


来源:https://stackoverflow.com/questions/45243873/dropwizard-admin-change-loglevel-for-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!