From 2b26886b17c6c98c98a3d81f59f766b06f1502f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 19 Oct 2021 09:13:14 +0200 Subject: [PATCH] null logger --- config/src/main/java/module-info.java | 3 ++- .../main/java/org/xbib/config/ConfigLoader.java | 2 +- .../java/org/xbib/config/NullConfigLogger.java | 16 ++++++++++++++++ .../services/org.xbib.config.ConfigLogger | 1 + .../datastructures/DatastructureSettings.java | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 config/src/main/java/org/xbib/config/NullConfigLogger.java rename config/src/{main => test}/resources/META-INF/services/org.xbib.config.ConfigLogger (50%) diff --git a/config/src/main/java/module-info.java b/config/src/main/java/module-info.java index ef13722..d365de4 100644 --- a/config/src/main/java/module-info.java +++ b/config/src/main/java/module-info.java @@ -1,4 +1,5 @@ import org.xbib.config.ConfigLogger; +import org.xbib.config.NullConfigLogger; import org.xbib.config.SystemConfigLogger; import org.xbib.settings.SettingsLoader; @@ -6,7 +7,7 @@ module org.xbib.config { exports org.xbib.config; uses ConfigLogger; uses SettingsLoader; - provides ConfigLogger with SystemConfigLogger; + provides ConfigLogger with NullConfigLogger, SystemConfigLogger; requires org.xbib.settings.api; requires transitive org.xbib.settings.datastructures; } diff --git a/config/src/main/java/org/xbib/config/ConfigLoader.java b/config/src/main/java/org/xbib/config/ConfigLoader.java index 24882e1..15657fb 100644 --- a/config/src/main/java/org/xbib/config/ConfigLoader.java +++ b/config/src/main/java/org/xbib/config/ConfigLoader.java @@ -40,7 +40,7 @@ public class ConfigLoader { private static ConfigLogger createConfigLogger() { ServiceLoader serviceLoader = ServiceLoader.load(ConfigLogger.class); Optional optionalConfigLogger = serviceLoader.findFirst(); - return optionalConfigLogger.orElse(new SystemConfigLogger()); + return optionalConfigLogger.orElse(new NullConfigLogger()); } private static final ConfigLoader configLoader = new ConfigLoader().withLogger(createConfigLogger()); diff --git a/config/src/main/java/org/xbib/config/NullConfigLogger.java b/config/src/main/java/org/xbib/config/NullConfigLogger.java new file mode 100644 index 0000000..e6279dc --- /dev/null +++ b/config/src/main/java/org/xbib/config/NullConfigLogger.java @@ -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) { + } +} diff --git a/config/src/main/resources/META-INF/services/org.xbib.config.ConfigLogger b/config/src/test/resources/META-INF/services/org.xbib.config.ConfigLogger similarity index 50% rename from config/src/main/resources/META-INF/services/org.xbib.config.ConfigLogger rename to config/src/test/resources/META-INF/services/org.xbib.config.ConfigLogger index b57351d..3fc2a28 100644 --- a/config/src/main/resources/META-INF/services/org.xbib.config.ConfigLogger +++ b/config/src/test/resources/META-INF/services/org.xbib.config.ConfigLogger @@ -1 +1,2 @@ +org.xbib.config.NullConfigLogger org.xbib.config.SystemConfigLogger \ No newline at end of file diff --git a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java index 5b53813..a890f36 100644 --- a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java +++ b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java @@ -17,7 +17,7 @@ public class DatastructureSettings implements Settings { private final TinyMap map; - protected DatastructureSettings(TinyMap map) { + DatastructureSettings(TinyMap map) { this.map = map; }