Author: chetanm
Date: Mon Feb 24 13:13:47 2014
New Revision: 1571273
URL: http://svn.apache.org/r1571273
Log:
SLING-3410 - Log the Logback initialization related logs to normal log for
transient errors
implemented a custom print logic which routes the status log to normal logger
or system out depending on logback initialization status
Added:
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java
(with props)
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=1571273&r1=1571272&r2=1571273&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 24 13:13:47 2014
@@ -1,7 +1,6 @@
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;
@@ -27,20 +26,17 @@ 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;
import
org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender;
+import org.apache.sling.commons.log.logback.internal.util.SlingStatusPrinter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -341,33 +337,7 @@ public class LogbackManager extends Logg
cb.fallbackConfiguration(eventList, createConfigurator(),
statusListener);
}
getStatusManager().remove(statusListener);
- 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);
- }
+
SlingStatusPrinter.printInCaseOfErrorsOrWarnings(getLoggerContext(),
resetStartTime, startTime, success);
}
}
Added:
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java?rev=1571273&view=auto
==============================================================================
---
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java
(added)
+++
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java
Mon Feb 24 13:13:47 2014
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.commons.log.logback.internal.util;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.status.ErrorStatus;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.status.StatusUtil;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Custom StatusPrinter similar to Logback StatusPrinter to account for
changes required
+ * for SLING-3410
+ */
+public class SlingStatusPrinter {
+
+ /**
+ * 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
+ * @param initSuccess flag indicating if Logback configuration failed or
not
+ */
+ public static void printInCaseOfErrorsOrWarnings(Context context, long
threshold,
+ long msgSince, boolean
initSuccess) {
+ 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) {
+ List<Status> filteredList =
+
StatusUtil.filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), msgSince);
+ print(filteredList, initSuccess);
+ }
+ }
+ }
+
+ private static void print(List<Status> statusList, boolean initSuccess) {
+ if (statusList == null) {
+ return;
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ if (initSuccess) {
+ sb.append("While (re)configuring Logback transient issues were
observed. " +
+ "More details are provided below.");
+ sb.append(CoreConstants.LINE_SEPARATOR);
+ }
+
+ for (Status s : statusList) {
+ StatusPrinter.buildStr(sb, "", s);
+ }
+
+ //In case logging system completely fails then log the message in
System out
+ //otherwise make it part of 'normal' logs
+ if (!initSuccess) {
+ System.out.println(sb.toString());
+ } else {
+ Logger logger = LoggerFactory.getLogger(SlingStatusPrinter.class);
+ logger.info(sb.toString());
+ }
+ }
+}
Propchange:
sling/trunk/bundles/commons/log/src/main/java/org/apache/sling/commons/log/logback/internal/util/SlingStatusPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native