[logback-dev] svn commit: r1767 - in logback/trunk: logback-classic/src/main/java/org/slf4j/impl logback-core/src/main/java/ch/qos/logback/core/util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Tue Aug 19 22:04:30 CEST 2008
Author: ceki
Date: Tue Aug 19 22:04:30 2008
New Revision: 1767
Modified:
logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
Log:
- in logback-classic, print internal status if errors were encountered
Modified: logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java (original)
+++ logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java Tue Aug 19 22:04:30 2008
@@ -64,8 +64,9 @@
// TODO test me
Util.reportFailure("Failed to auto configure default logger context",
je);
- StatusPrinter.print(defaultLoggerContext);
}
+ StatusPrinter.printIfErrorsOccured(defaultLoggerContext);
+
// See if a special context selector is needed
String contextSelectorStr = OptionHelper.getSystemProperty(
ClassicGlobal.LOGBACK_CONTEXT_SELECTOR, null);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java Tue Aug 19 22:04:30 2008
@@ -18,6 +18,7 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreGlobal;
import ch.qos.logback.core.Layout;
+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.helpers.ThrowableToStringArray;
@@ -33,6 +34,33 @@
ps = printStream;
}
+ /**
+ * Print the contents of the context statuses, but only if they
+ * contain errors.
+ *
+ * @param context
+ */
+ public static void printIfErrorsOccured(Context context) {
+ if (context == null) {
+ throw new IllegalArgumentException("Context argument cannot be null");
+ }
+
+ StatusManager sm = context.getStatusManager();
+ if (sm == null) {
+ ps.println("WARN: Context named \"" + context.getName()
+ + "\" has no status manager");
+ } else {
+ if (sm.getLevel() == ErrorStatus.ERROR) {
+ print(sm);
+ }
+ }
+ }
+
+ /**
+ * Print the contents of the context's status data.
+ *
+ * @param context
+ */
public static void print(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context argument cannot be null");
More information about the logback-dev
mailing list