incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1566627 - /sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/LogbackManager.java
Date Mon, 10 Feb 2014 14:05:59 GMT
Author: chetanm
Date: Mon Feb 10 14:05:58 2014
New Revision: 1566627

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

Adding more logs for debugging case when a failure occurs

Modified:
    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/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=1566627&r1=1566626&r2=1566627&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 14:05:58 2014
@@ -1,6 +1,7 @@
 package org.apache.sling.commons.log.logback.internal;
 
 import java.io.File;
+import java.io.PrintStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -26,13 +27,16 @@ import ch.qos.logback.classic.spi.Logger
 import ch.qos.logback.classic.turbo.TurboFilter;
 import ch.qos.logback.classic.util.EnvUtil;
 import ch.qos.logback.core.Appender;
+import ch.qos.logback.core.Context;
 import ch.qos.logback.core.joran.GenericConfigurator;
 import ch.qos.logback.core.joran.event.SaxEvent;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
 import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.status.ErrorStatus;
 import ch.qos.logback.core.status.OnConsoleStatusListener;
 import ch.qos.logback.core.status.StatusListener;
 import ch.qos.logback.core.status.StatusListenerAsList;
+import ch.qos.logback.core.status.StatusManager;
 import ch.qos.logback.core.status.StatusUtil;
 import ch.qos.logback.core.util.StatusPrinter;
 import org.apache.sling.commons.log.logback.internal.AppenderTracker.AppenderInfo;
@@ -264,6 +268,7 @@ public class LogbackManager extends Logg
 
     public void fireResetCompleteListeners(){
         for(LogbackResetListener listener : resetListeners){
+            addInfo("Firing reset listener - onResetComplete"+listener.getClass());
             listener.onResetComplete(getLoggerContext());
         }
     }
@@ -305,6 +310,7 @@ public class LogbackManager extends Logg
     }
 
     private void configure(ConfiguratorCallback cb) {
+        long startTime = System.currentTimeMillis();
         StatusListener statusListener = new StatusListenerAsList();
         if (debug) {
             statusListener = new OnConsoleStatusListener();
@@ -335,7 +341,33 @@ public class LogbackManager extends Logg
                 cb.fallbackConfiguration(eventList, createConfigurator(), statusListener);
             }
             getStatusManager().remove(statusListener);
-            StatusPrinter.printInCaseOfErrorsOrWarnings(getLoggerContext(), resetStartTime);
+            printInCaseOfErrorsOrWarnings(getLoggerContext(), resetStartTime, startTime);
+        }
+    }
+
+
+    /**
+     * Based on StatusPrinter. printInCaseOfErrorsOrWarnings. This has been adapted
+     * to print more context i.e. some message from before the error message to better understand
+     * the failure scenario
+     *
+     * @param threshold time since which the message have to be checked for errors/warnings
+     * @param msgSince time form which we are interested in the message logs
+     */
+    private static void printInCaseOfErrorsOrWarnings(Context context, long threshold, long
msgSince) {
+        if (context == null) {
+            throw new IllegalArgumentException("Context argument cannot be null");
+        }
+        PrintStream ps = System.out;
+        StatusManager sm = context.getStatusManager();
+        if (sm == null) {
+            ps.println("WARN: Context named \"" + context.getName()
+                    + "\" has no status manager");
+        } else {
+            StatusUtil statusUtil = new StatusUtil(context);
+            if (statusUtil.getHighestLevel(threshold) >= ErrorStatus.WARN) {
+                StatusPrinter.print(sm, msgSince);
+            }
         }
     }
 
@@ -467,14 +499,15 @@ public class LogbackManager extends Logg
             rootLogger.setLevel(Level.INFO);
             rootLogger.addAppender(logConfigManager.getDefaultAppender());
 
-
             // Now record the time of reset with a default appender attached to
             // root logger. We also add a milli second extra to account for logs which would
have
             // got fired in same duration
             resetStartTime = System.currentTimeMillis() + TimeUnit.MILLISECONDS.toMillis(1);
+            addInfo("Registered a default console based logger");
 
             context.putObject(LogbackManager.class.getName(), LogbackManager.this);
             for (LogbackResetListener l : resetListeners) {
+                addInfo("Firing reset listener - onResetStart"+l.getClass());
                 l.onResetStart(context);
             }
         }
@@ -504,6 +537,7 @@ public class LogbackManager extends Logg
             //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);
+                addInfo("Found appender attached with root logger. Detaching the default
console based logger");
             } else {
                 addInfo("No appender was found to be associated with root logger. Registering
" +
                         "a Console based logger");



Mime
View raw message