Skip to content

Commit

Permalink
Changing the delegate of substituted loggers post initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chetanmeh committed Feb 3, 2014
1 parent ca68555 commit 4f1bf59
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions slf4j-api/src/main/java/org/slf4j/LoggerFactory.java
Expand Up @@ -29,6 +29,7 @@
import java.util.*;

import org.slf4j.helpers.NOPLoggerFactory;
import org.slf4j.helpers.SubstitutableLogger;
import org.slf4j.helpers.SubstituteLoggerFactory;
import org.slf4j.helpers.Util;
import org.slf4j.impl.StaticLoggerBinder;
Expand Down Expand Up @@ -128,7 +129,7 @@ private final static void bind() {
StaticLoggerBinder.getSingleton();
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
reportActualBinding(staticLoggerBinderPathSet);
emitSubstituteLoggerWarning();
fixSubstitutedLoggers();
} catch (NoClassDefFoundError ncde) {
String msg = ncde.getMessage();
if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
Expand Down Expand Up @@ -161,18 +162,24 @@ static void failedBinding(Throwable t) {
Util.report("Failed to instantiate SLF4J LoggerFactory", t);
}

private final static void emitSubstituteLoggerWarning() {
List loggerNameList = TEMP_FACTORY.getLoggerNameList();
if (loggerNameList.size() == 0) {
private final static void fixSubstitutedLoggers() {
List<SubstitutableLogger> loggers = TEMP_FACTORY.getLoggers();

if(loggers.isEmpty()){
return;
}
Util.report("The following loggers will not work because they were created");
Util.report("during the default configuration phase of the underlying logging system.");

Util.report("The following set of substitute loggers may have been accessed");
Util.report("during the initialization phase and logging calls during this");
Util.report("phase were not honored but that calls in the future to these loggers");
Util.report("will be honored.");
Util.report("See also " + SUBSTITUTE_LOGGER_URL);
for (int i = 0; i < loggerNameList.size(); i++) {
String loggerName = (String) loggerNameList.get(i);
Util.report(loggerName);
for(SubstitutableLogger subLogger : loggers){
subLogger.setDelegate(getLogger(subLogger.getName()));
Util.report(subLogger.getName());
}

TEMP_FACTORY.clear();
}

private final static void versionSanityCheck() {
Expand Down

0 comments on commit 4f1bf59

Please sign in to comment.