From 8b97b0a2dae4ab8b8b5cc614ca58b329af2ce6ff Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Mon, 18 Mar 2013 18:57:04 +0000 Subject: [PATCH] Fix call to SimpleLoggerFactory.reset method (use LoggerFactory to make sure we get the right instance to reset, as SimpleLoggerFactory.INSTANCE is not actually used by slf4j-simple's StaticLoggerBinder) and remove temporary reflection workaround Signed-off-by: Jason van Zyl --- .../logging/impl/Slf4jSimpleConfiguration.java | 15 --------------- .../org/slf4j/impl/MavenSlf4jSimpleFriend.java | 9 ++++++++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java index 402d56220d..6a7f38518e 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java @@ -58,20 +58,5 @@ public class Slf4jSimpleConfiguration // property for root logger level or System.out redirection need to be taken into account MavenSlf4jFriend.reset(); MavenSlf4jSimpleFriend.init(); - - try - { - org.slf4j.ILoggerFactory loggerFactory = org.slf4j.LoggerFactory.getILoggerFactory(); - synchronized ( loggerFactory ) - { - java.lang.reflect.Field loggerMap = loggerFactory.getClass().getDeclaredField( "loggerMap" ); - loggerMap.setAccessible( true ); - ( (java.util.Map) loggerMap.get( loggerFactory ) ).clear(); - } - } - catch ( Exception e ) - { - // ignore for now... - } } } diff --git a/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java b/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java index 3299fc86ba..bffd18c676 100644 --- a/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java +++ b/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java @@ -19,6 +19,9 @@ package org.slf4j.impl; * under the License. */ +import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; + /** * Utility for Maven to access Slf4j-Simple internals through package access. * Use with precaution, since this is not normally intended for production use. @@ -28,6 +31,10 @@ public class MavenSlf4jSimpleFriend public static void init() { SimpleLogger.init(); - SimpleLoggerFactory.INSTANCE.reset(); + ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); + if ( loggerFactory instanceof SimpleLoggerFactory ) + { + ( (SimpleLoggerFactory) loggerFactory ).reset(); + } } }