All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.elsci.mocks.web.tomcat.Slf4jOverJulPropogator Maven / Gradle / Ivy

There is a newer version: 20231025.1145-36
Show newest version
package io.elsci.mocks.web.tomcat;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.springframework.context.Lifecycle;

/**
 * Need to figure out exactly what's wrong without this class and add details to the docs.
 *
 * jul-to-slf4j bridge cannot replace classes in the java.util.logging package to do the redirection
 * statically as it does for the other bridge implementations. Instead, it has to register a handler on
 * the root logger and listen for logging statements like any other handler. It will then redirect
 * those logging statements.
 */
public class Slf4jOverJulPropogator implements LoggerContextListener, Lifecycle {

    private boolean isRunning = false;

    @Override
    public boolean isResetResistant() {
        return true;
    }

    @Override
    public void onStart(LoggerContext loggerContext) {
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
        isRunning = true;
    }

    @Override
    public void onReset(LoggerContext loggerContext) {

    }

    @Override
    public void onStop(LoggerContext loggerContext) {

    }

    @Override
    public void onLevelChange(Logger logger, Level level) {

    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {

    }

    @Override
    public boolean isRunning() {
        return isRunning;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy