null logger

This commit is contained in:
Jörg Prante 2021-10-19 09:13:14 +02:00
parent 0bd3e98253
commit 2b26886b17
5 changed files with 21 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import org.xbib.config.ConfigLogger; import org.xbib.config.ConfigLogger;
import org.xbib.config.NullConfigLogger;
import org.xbib.config.SystemConfigLogger; import org.xbib.config.SystemConfigLogger;
import org.xbib.settings.SettingsLoader; import org.xbib.settings.SettingsLoader;
@ -6,7 +7,7 @@ module org.xbib.config {
exports org.xbib.config; exports org.xbib.config;
uses ConfigLogger; uses ConfigLogger;
uses SettingsLoader; uses SettingsLoader;
provides ConfigLogger with SystemConfigLogger; provides ConfigLogger with NullConfigLogger, SystemConfigLogger;
requires org.xbib.settings.api; requires org.xbib.settings.api;
requires transitive org.xbib.settings.datastructures; requires transitive org.xbib.settings.datastructures;
} }

View file

@ -40,7 +40,7 @@ public class ConfigLoader {
private static ConfigLogger createConfigLogger() { private static ConfigLogger createConfigLogger() {
ServiceLoader<ConfigLogger> serviceLoader = ServiceLoader.load(ConfigLogger.class); ServiceLoader<ConfigLogger> serviceLoader = ServiceLoader.load(ConfigLogger.class);
Optional<ConfigLogger> optionalConfigLogger = serviceLoader.findFirst(); Optional<ConfigLogger> optionalConfigLogger = serviceLoader.findFirst();
return optionalConfigLogger.orElse(new SystemConfigLogger()); return optionalConfigLogger.orElse(new NullConfigLogger());
} }
private static final ConfigLoader configLoader = new ConfigLoader().withLogger(createConfigLogger()); private static final ConfigLoader configLoader = new ConfigLoader().withLogger(createConfigLogger());

View file

@ -0,0 +1,16 @@
package org.xbib.config;
public class NullConfigLogger implements ConfigLogger {
@Override
public void info(String string) {
}
@Override
public void warn(String message) {
}
@Override
public void error(String message) {
}
}

View file

@ -1 +1,2 @@
org.xbib.config.NullConfigLogger
org.xbib.config.SystemConfigLogger org.xbib.config.SystemConfigLogger

View file

@ -17,7 +17,7 @@ public class DatastructureSettings implements Settings {
private final TinyMap<String, String> map; private final TinyMap<String, String> map;
protected DatastructureSettings(TinyMap<String, String> map) { DatastructureSettings(TinyMap<String, String> map) {
this.map = map; this.map = map;
} }