Skip to content

Commit

Permalink
refactoring: combining Module and Provider for non-deprecated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Nov 25, 2023
1 parent f9a3f8b commit ab97827
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.logback.LogbackModuleProvider;
import io.bootique.logback.LogbackModule;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -42,6 +42,6 @@ public BuiltModule buildModule() {
@Override
@Deprecated(since = "3.0", forRemoval = true)
public Collection<BQModuleProvider> dependencies() {
return Collections.singletonList(new LogbackModuleProvider());
return Collections.singletonList(new LogbackModule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
package io.bootique.logback;

import ch.qos.logback.classic.Logger;
import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.annotation.LogLevels;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.shutdown.ShutdownManager;
Expand All @@ -31,11 +33,16 @@
import javax.inject.Singleton;
import java.util.Map;

public class LogbackModule extends ConfigModule {
public class LogbackModule implements BQModule, BQModuleProvider {

private static final String CONFIG_PREFIX = "log";

@Override
protected String defaultConfigPrefix() {
return "log";
public BuiltModule buildModule() {
return BuiltModule.of(this)
.description("Integrates Logback logging library")
.config(CONFIG_PREFIX, LogbackContextFactory.class)
.build();
}

@Override
Expand All @@ -47,11 +54,13 @@ public void configure(Binder binder) {

@Singleton
@Provides
Logger provideRootLogger(ConfigurationFactory configFactory,
ShutdownManager shutdownManager,
@LogLevels Map<String, java.util.logging.Level> defaultLevels) {
Logger provideRootLogger(
ConfigurationFactory configFactory,
ShutdownManager shutdownManager,
@LogLevels Map<String, java.util.logging.Level> defaultLevels) {

return config(LogbackContextFactory.class, configFactory)
return configFactory
.config(LogbackContextFactory.class, CONFIG_PREFIX)
.createRootLogger(shutdownManager, defaultLevels);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
#####################################################################
# Licensed to ObjectStyle LLC under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ObjectStyle LLC licenses
# this file to you under the Apache License, Version 2.0 (the
# “License”); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#####################################################################

io.bootique.logback.LogbackModuleProvider
io.bootique.logback.LogbackModule
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import io.bootique.junit5.BQModuleProviderChecker;
import org.junit.jupiter.api.Test;

public class LogbackModuleProviderIT {
public class LogbackModuleTest {

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(LogbackModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(LogbackModule.class);
}

@Test
public void metadata() {
BQModuleProviderChecker.testMetadata(LogbackModuleProvider.class);
BQModuleProviderChecker.testMetadata(LogbackModule.class);
}
}

0 comments on commit ab97827

Please sign in to comment.