io.bootique.logback.LogbackModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bootique-logback Show documentation
Show all versions of bootique-logback Show documentation
Provides Logback integration with Bootique
package io.bootique.logback;
import ch.qos.logback.classic.Logger;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import io.bootique.ConfigModule;
import io.bootique.annotation.LogLevels;
import io.bootique.config.ConfigurationFactory;
import io.bootique.shutdown.ShutdownManager;
import java.util.Map;
public class LogbackModule extends ConfigModule {
public LogbackModule(String configPrefix) {
super(configPrefix);
}
public LogbackModule() {
}
@Override
protected String defaultConfigPrefix() {
return "log";
}
@Override
public void configure(Binder binder) {
// Binding a dummy class to trigger eager init of Logback as
// @Provides below can not be invoked eagerly..
binder.bind(LogInitTrigger.class).asEagerSingleton();
}
@Singleton
@Provides
Logger provideRootLogger(ConfigurationFactory configFactory,
ShutdownManager shutdownManager,
@LogLevels Map defaultLevels) {
return configFactory
.config(LogbackContextFactory.class, configPrefix)
.createRootLogger(shutdownManager, defaultLevels);
}
static class LogInitTrigger {
@Inject
public LogInitTrigger(Logger rootLogger) {
rootLogger.debug("Logback started");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy