From 7ee6c7f3a17113930474b2f83c17a0ac7a2f56f1 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 24 Apr 2020 09:29:11 +0300 Subject: [PATCH] Introduce the ability to use a custom logger Relates to: https://github.com/quarkusio/quarkus/issues/8798 --- core/src/main/java/io/dekorate/Session.java | 15 ++++++++-- .../java/io/dekorate/logger/NoopLogger.java | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/io/dekorate/logger/NoopLogger.java diff --git a/core/src/main/java/io/dekorate/Session.java b/core/src/main/java/io/dekorate/Session.java index 4607e4f41..0381119fe 100644 --- a/core/src/main/java/io/dekorate/Session.java +++ b/core/src/main/java/io/dekorate/Session.java @@ -64,19 +64,27 @@ public class Session { private final AtomicReference writer = new AtomicReference<>(); private final Map, SessionListener> listeners = new HashMap<>(); - private final Logger LOGGER = LoggerFactory.getLogger(); + private final Logger LOGGER; /** * Creates or reuses a single instance of Session. * @return The Session. */ public static Session getSession() { + return getSession(LoggerFactory.getLogger()); + } + + /** + * Creates or reuses a single instance of Session. + * @return The Session. + */ + public static Session getSession(Logger logger) { if (INSTANCE != null) { return INSTANCE; } synchronized (Session.class) { if (INSTANCE == null) { - INSTANCE = new Session(); + INSTANCE = new Session(logger); INSTANCE.loadHandlers(); INSTANCE.loadGenerators(); } @@ -84,7 +92,8 @@ public static Session getSession() { return INSTANCE; } - protected Session() { + protected Session(Logger logger) { + LOGGER = logger; LOGGER.info("Initializing dekorate session."); } diff --git a/core/src/main/java/io/dekorate/logger/NoopLogger.java b/core/src/main/java/io/dekorate/logger/NoopLogger.java new file mode 100644 index 000000000..b8e3e3563 --- /dev/null +++ b/core/src/main/java/io/dekorate/logger/NoopLogger.java @@ -0,0 +1,29 @@ +package io.dekorate.logger; + +import io.dekorate.Logger; + +/** + * Used to suppress logging completely + */ +public class NoopLogger implements Logger { + + @Override + public void debug(String message) { + + } + + @Override + public void info(String message) { + + } + + @Override + public void warning(String message) { + + } + + @Override + public void error(String message) { + + } +}