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 <jason@tesla.io>
This commit is contained in:
Stuart McCulloch 2013-03-18 18:57:04 +00:00 committed by Jason van Zyl
parent 2ec0a6b69f
commit 8b97b0a2da
2 changed files with 8 additions and 16 deletions

View File

@ -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...
}
}
}

View File

@ -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();
}
}
}