From edfe3010805989da52fce3401c4cfb0eba0f7eaa Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 26 May 2019 15:20:32 +0100 Subject: [PATCH] prevent duplicate logs --- .../muwire/core/util/MuWireLogManager.groovy | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/util/MuWireLogManager.groovy b/core/src/main/groovy/com/muwire/core/util/MuWireLogManager.groovy index f087c8f2..c00ca6fc 100644 --- a/core/src/main/groovy/com/muwire/core/util/MuWireLogManager.groovy +++ b/core/src/main/groovy/com/muwire/core/util/MuWireLogManager.groovy @@ -6,16 +6,31 @@ import net.i2p.util.LogManager class MuWireLogManager extends LogManager { + private static final Map, Log> classLogs = new HashMap<>() + private static final Map stringLogs = new HashMap<>() + MuWireLogManager() { super(I2PAppContext.getGlobalContext()) } @Override - public Log getLog(Class cls, String name) { - if (cls != null) - return new JULLog(cls) - new JULLog(name) + public synchronized Log getLog(Class cls, String name) { + if (cls != null) { + Log rv = classLogs.get(cls) + if (rv == null) { + rv = new JULLog(cls) + classLogs.put(cls, rv) + } + return rv + } + + Log rv = stringLogs.get(name) + if (rv == null) { + rv = new JULLog(name) + stringLogs.put(name, rv) + } + rv } }