Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropwizard Admin: Change loglevel for all

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?

like image 495
Kousha Avatar asked Jul 21 '17 17:07

Kousha


People also ask

How do you change Loglevel?

To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)

How do you change the log level in log4j2 at runtime?

You can set a logger's level with the class Configurator from Log4j Core. BUT be aware that the Configurator class is not part of the public API. If you wish to change the root logger level, do something like this : LoggerContext ctx = (LoggerContext) LogManager.

Does Dropwizard use Log4j?

Dropwizard uses Logback for its logging backend. It provides an slf4j implementation, and even routes all java. util. logging , Log4j, and Apache Commons Logging usage through Logback.


Video Answer


1 Answers

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
like image 79
victorcampos Avatar answered Oct 13 '22 00:10

victorcampos