package stroom.dashboard.server.logging;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import com.codahale.metrics.health.HealthCheck;
import org.slf4j.LoggerFactory;
import stroom.resources.HasHealthCheck;

import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

public enum LogLevelInspector implements HasHealthCheck {

    INSTANCE;

    public HealthCheck.Result getHealth() {

        LoggerContext loggerContext = ((LoggerContext) LoggerFactory.getILoggerFactory());

        if (loggerContext != null) {
            //use a treemap so se get the levels nicely sorted
            Map<String, String> levels = loggerContext.getLoggerList().stream()
                    .filter(logger -> logger.getLevel() != null)
                    .collect(Collectors.toMap(
                            Logger::getName,
                            logger -> logger.getLevel().levelStr,
                            (v1, v2) -> v1 + ", " + v2, //don't think we will ever get dups, but just in case concat them
                            TreeMap::new));

            return HealthCheck.Result.builder()
                    .healthy()
                    .withDetail("levels", levels)
                    .build();
        } else {
            return HealthCheck.Result.unhealthy("Unable to obtain levels, LoggerContext is null");
        }
    }
}

@@ -324,16 +324,345 @@
 ctors;%0A%0A
+/**%0A * Class to present all the defined log levels as a health check so you can view all log levels as%0A * they are at run time. Log levels can be changed using 'httpie' like this:%0A * http -f POST http://127.0.0.1:8080/admin/tasks/log-level logger=stroom.statistics.internal.MultiServiceInternalStatisticsReceiver level=TRACE%0A */%0A
 public e

Add java doc to LogLevelInspector