Dropwizard Admin: Change loglevel for all

2019-04-14 06:40发布

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条回答
孤傲高冷的网名
2楼-- · 2019-04-14 06:56

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
查看更多
登录 后发表回答