[logback-dev] svn commit: r1780 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/pattern logback-classic/src/main/java/ch/qos/logback/classic/pattern

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Aug 27 14:09:34 CEST 2008


Author: ceki
Date: Wed Aug 27 14:09:33 2008
New Revision: 1780

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/EnsureLineSeparation.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java

Log:
LBCLASSIC-67

Other missing files

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/EnsureLineSeparation.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/EnsureLineSeparation.java	Wed Aug 27 14:09:33 2008
@@ -0,0 +1,34 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.access.pattern;
+
+import ch.qos.logback.access.spi.AccessEvent;
+import ch.qos.logback.core.pattern.Converter;
+import ch.qos.logback.core.pattern.ConverterUtil;
+import ch.qos.logback.core.pattern.PostCompileProcessor;
+
+public class EnsureLineSeparation implements PostCompileProcessor<AccessEvent> {
+
+  /**
+   * Add a line separator converter so that access event appears on a separate
+   * line.
+   */
+  public void process(Converter<AccessEvent> head) {
+    Converter<AccessEvent> tail = ConverterUtil.findTail(head);
+    Converter<AccessEvent> newLineConverter = new LineSeparatorConverter();
+    if (tail == null) {
+      head = newLineConverter;
+    } else {
+      if (!(tail instanceof LineSeparatorConverter)) {
+        tail.setNext(newLineConverter);
+      }
+    }
+  }
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java	Wed Aug 27 14:09:33 2008
@@ -0,0 +1,60 @@
+package ch.qos.logback.classic.pattern;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.pattern.Converter;
+import ch.qos.logback.core.pattern.ConverterUtil;
+import ch.qos.logback.core.pattern.PostCompileProcessor;
+
+public class EnsureExceptionHandling implements PostCompileProcessor<LoggingEvent> {
+
+//  public void process(Converter head) {
+//    // TODO Auto-generated method stub
+//
+//  }
+  
+  /**
+   * This implementation checks if any of the converters in the chain handles
+   * exceptions. If not, then this method adds a ThrowableInformationConverter
+   * instance to the end of the chain.
+   * <p>
+   * This allows appenders using this layout to output exception information
+   * event if the user forgets to add %ex to the pattern. Note that the
+   * appenders defined in the Core package are not aware of exceptions nor
+   * LoggingEvents.
+   * <p>
+   * If for some reason the user wishes to NOT print exceptions, then she can
+   * add %nopex to the pattern.
+   * 
+   * 
+   */
+  public void process(Converter<LoggingEvent> head) {
+    if (!chainHandlesThrowable(head)) {
+      Converter<LoggingEvent> tail = ConverterUtil.findTail(head);
+      Converter<LoggingEvent> exConverter = new ThrowableInformationConverter();
+      if (tail == null) {
+        head = exConverter;
+      } else {
+        tail.setNext(exConverter);
+      }
+    }
+  }
+
+  /**
+   * This method computes whether a chain of converters handles exceptions or
+   * not.
+   * 
+   * @param head
+   *          The first element of the chain
+   * @return true if can handle throwables contained in logging events
+   */
+  public boolean chainHandlesThrowable(Converter head) {
+    Converter c = head;
+    while (c != null) {
+      if (c instanceof ThrowableHandlingConverter) {
+        return true;
+      }
+      c = c.getNext();
+    }
+    return false;
+  }
+}


More information about the logback-dev mailing list