[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-106-g130277b

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Mon Mar 22 17:47:26 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  130277bce03f608db7ab555ec28705f9fc974e1e (commit)
      from  39dbbf9a5f7d414db63e89b18d09d04fd0ae6498 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=130277bce03f608db7ab555ec28705f9fc974e1e
http://github.com/ceki/logback/commit/130277bce03f608db7ab555ec28705f9fc974e1e

commit 130277bce03f608db7ab555ec28705f9fc974e1e
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Mon Mar 22 17:46:26 2010 +0100

    Fixed LBCLASSIC-170

diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
index e563109..7c92e50 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
@@ -25,15 +25,18 @@ import java.util.Set;
 import ch.qos.logback.classic.db.names.DBNameResolver;
 import ch.qos.logback.classic.db.names.DefaultDBNameResolver;
 import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.spi.IThrowableProxy;
 import ch.qos.logback.classic.spi.StackTraceElementProxy;
+import ch.qos.logback.classic.spi.ThrowableProxyUtil;
+import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.db.DBAppenderBase;
 
 /**
  * The DBAppender inserts logging events into three database tables in a format
- * independent of the Java programming language. 
+ * independent of the Java programming language.
  * 
- * For more information about this appender, please refer to the online manual at
- * http://logback.qos.ch/manual/appenders.html#DBAppender
+ * For more information about this appender, please refer to the online manual
+ * at http://logback.qos.ch/manual/appenders.html#DBAppender
  * 
  * @author Ceki G&uuml;lc&uuml;
  * @author Ray DeCampo
@@ -51,7 +54,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     // PreparedStatement.getGeneratedKeys() method was added in JDK 1.4
     Method getGeneratedKeysMethod;
     try {
-      // the 
+      // the
       getGeneratedKeysMethod = PreparedStatement.class.getMethod(
           "getGeneratedKeys", (Class[]) null);
     } catch (Exception ex) {
@@ -59,7 +62,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     }
     GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
   }
-  
+
   public DBAppender() {
   }
 
@@ -69,7 +72,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
 
   @Override
   public void start() {
-    if(dbNameResolver == null)
+    if (dbNameResolver == null)
       dbNameResolver = new DefaultDBNameResolver();
     insertExceptionSQL = SQLBuilder.buildInsertExceptionSQL(dbNameResolver);
     insertPropertiesSQL = SQLBuilder.buildInsertPropertiesSQL(dbNameResolver);
@@ -85,7 +88,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     bindLoggingEventWithInsertStatement(insertStatement, event);
     // This is expensive... should we do it every time?
     bindCallerDataWithPreparedStatement(insertStatement, event.getCallerData());
-    
+
     int updateCount = insertStatement.executeUpdate();
     if (updateCount != 1) {
       addWarn("Failed to insert loggingEvent");
@@ -97,12 +100,12 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     insertProperties(mergedMap, connection, eventId);
 
     if (event.getThrowableProxy() != null) {
-      insertThrowable(event.getThrowableProxy().getStackTraceElementProxyArray(), connection, eventId);
+      insertThrowable(event.getThrowableProxy(), connection, eventId);
     }
   }
 
-  void bindLoggingEventWithInsertStatement(PreparedStatement stmt, ILoggingEvent event)
-      throws SQLException {
+  void bindLoggingEventWithInsertStatement(PreparedStatement stmt,
+      ILoggingEvent event) throws SQLException {
     stmt.setLong(1, event.getTimeStamp());
     stmt.setString(2, event.getFormattedMessage());
     stmt.setString(3, event.getLoggerName());
@@ -111,8 +114,8 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     stmt.setShort(6, DBHelper.computeReferenceMask(event));
   }
 
-  void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray)
-      throws SQLException {
+  void bindCallerDataWithPreparedStatement(PreparedStatement stmt,
+      StackTraceElement[] callerDataArray) throws SQLException {
     StackTraceElement callerData = callerDataArray[0];
     if (callerData != null) {
       stmt.setString(7, callerData.getFileName());
@@ -128,7 +131,8 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     // we consider that event-specific properties should have priority over
     // context-wide
     // properties.
-    Map<String, String> loggerContextMap = event.getLoggerContextVO().getPropertyMap();
+    Map<String, String> loggerContextMap = event.getLoggerContextVO()
+        .getPropertyMap();
     Map<String, String> mdcMap = event.getMDCPropertyMap();
     if (loggerContextMap != null) {
       mergedMap.putAll(loggerContextMap);
@@ -149,7 +153,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
   protected String getInsertSQL() {
     return insertSQL;
   }
-  
+
   protected void insertProperties(Map<String, String> mergedMap,
       Connection connection, int eventId) throws SQLException {
     Set propertiesKeys = mergedMap.keySet();
@@ -180,28 +184,71 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
       insertPropertiesStatement = null;
     }
   }
-  
-  protected void insertThrowable(StackTraceElementProxy[] stepArray, Connection connection,
+
+  /**
+   * Add an exception statement either as a batch or execute immediately if
+   * batch updates are not supported.
+   */
+  void updateExceptionStatement(PreparedStatement exceptionStatement,
+      String txt, short i, int eventId) throws SQLException {
+    exceptionStatement.setInt(1, eventId);
+    exceptionStatement.setShort(2, i);
+    exceptionStatement.setString(3, txt);
+    if (cnxSupportsBatchUpdates) {
+      exceptionStatement.addBatch();
+    } else {
+      exceptionStatement.execute();
+    }
+  }
+
+  short buildExceptionStatement(IThrowableProxy tp, short baseIndex,
+      PreparedStatement insertExceptionStatement, int eventId)
+      throws SQLException {
+
+    StringBuilder buf = new StringBuilder();
+    ThrowableProxyUtil.printFirstLine(buf, tp);
+    updateExceptionStatement(insertExceptionStatement, buf.toString(),
+        baseIndex++, eventId);
+
+    int commonFrames = tp.getCommonFrames();
+    StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
+    for (int i = 0; i < stepArray.length - commonFrames; i++) {
+      StringBuilder sb = new StringBuilder();
+      sb.append(CoreConstants.TAB);
+      ThrowableProxyUtil.printSTEP(sb, stepArray[i]);
+      updateExceptionStatement(insertExceptionStatement, sb.toString(),
+          baseIndex++, eventId);
+    }
+
+    if (commonFrames > 0) {
+      StringBuilder sb = new StringBuilder();
+      sb.append(CoreConstants.TAB).append("... ").append(commonFrames).append(
+          " common frames omitted");
+      updateExceptionStatement(insertExceptionStatement, sb.toString(),
+          baseIndex++, eventId);
+    }
+
+    return baseIndex;
+  }
+
+  protected void insertThrowable(IThrowableProxy tp, Connection connection,
       int eventId) throws SQLException {
 
-    PreparedStatement insertExceptionStatement = connection
+    PreparedStatement exceptionStatement = connection
         .prepareStatement(insertExceptionSQL);
 
-    for (short i = 0; i < stepArray.length; i++) {
-      insertExceptionStatement.setInt(1, eventId);
-      insertExceptionStatement.setShort(2, i);
-      insertExceptionStatement.setString(3, stepArray[i].toString());
-      if (cnxSupportsBatchUpdates) {
-        insertExceptionStatement.addBatch();
-      } else {
-        insertExceptionStatement.execute();
-      }
+    short baseIndex = 0;
+    while (tp != null) {
+      baseIndex = buildExceptionStatement(tp, baseIndex, exceptionStatement,
+          eventId);
+      tp = tp.getCause();
     }
+
     if (cnxSupportsBatchUpdates) {
-      insertExceptionStatement.executeBatch();
+      exceptionStatement.executeBatch();
     }
-    insertExceptionStatement.close();
-    insertExceptionStatement = null;
+    exceptionStatement.close();
+    exceptionStatement = null;
 
   }
 }
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverter.java b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverter.java
index a7e545c..4a841d7 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ExtendedThrowableProxyConverter.java
@@ -13,21 +13,16 @@
  */
 package ch.qos.logback.classic.pattern;
 
-import ch.qos.logback.classic.spi.ClassPackagingData;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.StackTraceElementProxy;
+import ch.qos.logback.classic.spi.ThrowableProxyUtil;
 
 public class ExtendedThrowableProxyConverter extends ThrowableProxyConverter {
 
   @Override
   protected void extraData(StringBuilder builder, StackTraceElementProxy step) {
-
     if (step != null) {
-      ClassPackagingData pi = step.getClassPackagingData();
-      if (pi != null) {
-        builder.append(" [").append(pi.getCodeLocation()).append(':').append(
-            pi.getVersion()).append(']');
-      }
+      ThrowableProxyUtil.appendPackagingData(builder, step);
     }
   }
 
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ThrowableProxyUtil.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ThrowableProxyUtil.java
index 5b45359..be8dc67 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ThrowableProxyUtil.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ThrowableProxyUtil.java
@@ -81,7 +81,7 @@ public class ThrowableProxyUtil {
     return sb.toString();
   }
 
-  static void appendPackagingData(StringBuilder builder, StackTraceElementProxy step) {
+  public static void appendPackagingData(StringBuilder builder, StackTraceElementProxy step) {
     if (step != null) {
       ClassPackagingData cpd = step.getClassPackagingData();
       if (cpd != null) {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
index 5d1f26b..e146669 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
@@ -76,14 +76,21 @@ public class DBAppenderIntegrationTest {
     for (int i = 1; i <= runLength; i++) {
       logger.debug("This is a debug message. Message number: " + i);
     }
-    logger.error("At last an error.", new Exception("Just testing"));
 
+    Exception e = new Exception("Just testing", getCause());
+    logger
+        .error("At last an error.", e);
+    e.printStackTrace();
     // check that there were no errors
     StatusPrinter.print(lc);
     assertEquals(Status.INFO, lc.getStatusManager().getLevel());
 
   }
 
+  Throwable getCause() {
+    return new IllegalStateException("test cause");
+  }
+
   static boolean isConformingHostAndJDK16OrHigher(String[] conformingHostList) {
     if (!Env.isJDK6OrHigher()) {
       return false;
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 912666c..664b15a 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -134,6 +134,17 @@
     reported by Tom SH Liu.
     </p>
 
+
+    <p>DBAppender now outputs exception class and message. It will
+    also output root causes, fixing
+    <a href="http://jira.qos.ch/browse/LBCLASSIC-170">LBCLASSIC-170</a>
+    reported by Tomasz Nurkiewicz.
+    </p>
+
+    <p>Fixed missing EVENT_ID column problem on PostgreSQL as reported
+    in <a href="http://jira.qos.ch/browse/LBCORE-126">LBCORE-126</a>
+    by Brian Edwards.</p>
+
     <p>Fixed <a
     href="http://jira.qos.ch/browse/LBSITE-36">LBSITE-36</a> reported
     by John Jimenez.</p>

-----------------------------------------------------------------------

Summary of changes:
 .../java/ch/qos/logback/classic/db/DBAppender.java |  105 ++++++++++++++------
 .../pattern/ExtendedThrowableProxyConverter.java   |    9 +--
 .../logback/classic/spi/ThrowableProxyUtil.java    |    2 +-
 .../classic/db/DBAppenderIntegrationTest.java      |    9 ++-
 logback-site/src/site/pages/news.html              |   11 ++
 5 files changed, 98 insertions(+), 38 deletions(-)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list