incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1566597 - in /sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal: LogConfigManager.java LogbackManager.java
Date Mon, 10 Feb 2014 12:43:33 GMT
Author: chetanm
Date: Mon Feb 10 12:43:32 2014
New Revision: 1566597

URL: http://svn.apache.org/r1566597
Log:
SLING-3045 - [logback]Warning logs logged for 'No appenders present in context [sling] for
logger'

Instead of removing the console logger asscoaited with root logger by default we check now
if root logger has any appender associated with it or not. if not then console logger is not
removed

Also moved this logic out as a separate listener and ensure that this listener is invoked
at the end of config cycle.

Modified:
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
    sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java?rev=1566597&r1=1566596&r2=1566597&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java
Mon Feb 10 12:43:32 2014
@@ -81,7 +81,7 @@ public class LogConfigManager implements
 
     public static final String FACTORY_PID_CONFIGS = PID + ".factory.config";
 
-    private static final String DEFAULT_CONSOLE_APPENDER_NAME = "org.apache.sling.commons.log.CONSOLE";
+    public static final String DEFAULT_CONSOLE_APPENDER_NAME = "org.apache.sling.commons.log.CONSOLE";
 
     private final LoggerContext loggerContext;
 
@@ -293,10 +293,6 @@ public class LogConfigManager implements
                 }
             }
         }
-
-        // Remove the default console appender that we attached at start of
-        // reset
-        context.getLogger(Logger.ROOT_LOGGER_NAME).detachAppender(DEFAULT_CONSOLE_APPENDER_NAME);
     }
 
 

Modified: sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java?rev=1566597&r1=1566596&r2=1566597&view=diff
==============================================================================
--- sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
(original)
+++ sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
Mon Feb 10 12:43:32 2014
@@ -145,6 +145,7 @@ public class LogbackManager extends Logg
         resetListeners.add(configSourceTracker);
         resetListeners.add(filterTracker);
         resetListeners.add(turboFilterTracker);
+        resetListeners.add(new RootLoggerListener()); //Should be invoked at last
 
         //Record trackers for shutdown later
         serviceTrackers.add(appenderTracker);
@@ -461,7 +462,7 @@ public class LogbackManager extends Logg
             context.setPackagingDataEnabled(logConfigManager.isPackagingDataEnabled());
 
             // Attach a console appender to handle logging untill we configure
-            // one. This would be removed in LogConfigManager.reset
+            // one. This would be removed in RootLoggerListener.reset
             final Logger rootLogger = getLoggerContext().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
             rootLogger.setLevel(Level.INFO);
             rootLogger.addAppender(logConfigManager.getDefaultAppender());
@@ -486,6 +487,30 @@ public class LogbackManager extends Logg
 
     }
 
+    private class RootLoggerListener implements LogbackResetListener {
+
+        @Override
+        public void onResetStart(LoggerContext context) {
+
+        }
+
+        @Override
+        public void onResetComplete(LoggerContext context) {
+            // Remove the default console appender that we attached at start of
+            // reset
+            ch.qos.logback.classic.Logger root = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
+            Iterator<Appender<ILoggingEvent>> appenderItr = root.iteratorForAppenders();
+
+            //Root logger has at least 1 appender associated with it. Remove the one added
by us
+            if (appenderItr.hasNext()) {
+                root.detachAppender(LogConfigManager.DEFAULT_CONSOLE_APPENDER_NAME);
+            } else {
+                addInfo("No appender was found to be associated with root logger. Registering
" +
+                        "a Console based logger");
+            }
+        }
+    }
+
     // ~--------------------------------Configurator Base
 
     private class SlingConfigurator extends JoranConfigurator {



Mime
View raw message