[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.27-7-gb8790fc

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Dec 30 17:05:41 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  b8790fc09eee12d16dcc0c8417df7d503927211f (commit)
      from  9fa097d645fe31bb057884c21c20f3e40617a8bd (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=b8790fc09eee12d16dcc0c8417df7d503927211f
http://github.com/ceki/logback/commit/b8790fc09eee12d16dcc0c8417df7d503927211f

commit b8790fc09eee12d16dcc0c8417df7d503927211f
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Dec 30 16:59:07 2010 +0100

    FIX BCLASSIC-239

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 0bbc74e..93e0c13 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
@@ -138,7 +138,7 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     int arrayLen = argArray != null ? argArray.length : 0;
     
     for(int i = 0; i < arrayLen && i < 4; i++) {
-      stmt.setString(ARG0_INDEX+i, truncateTo254(argArray[i].toString()));
+      stmt.setString(ARG0_INDEX+i, asStringTruncatedTo254(argArray[i]));
     }
     if(arrayLen < 4) {
       for(int i = arrayLen; i < 4; i++) {
@@ -147,7 +147,12 @@ public class DBAppender extends DBAppenderBase<ILoggingEvent> {
     }
   }
 
-  String truncateTo254(String s) {
+  String asStringTruncatedTo254(Object o) {
+     String s = null;
+     if(o != null) {
+         s= o.toString();
+     }
+
     if(s == null) {
       return null;
     }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
index f8daa42..f2a3606 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderH2Test.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.Date;
 import java.util.Map;
 
 import org.apache.log4j.MDC;
@@ -36,7 +37,7 @@ import ch.qos.logback.core.db.DriverManagerConnectionSource;
 import ch.qos.logback.core.testUtil.RandomUtil;
 import ch.qos.logback.core.util.StatusPrinter;
 
-public class DBAppenderH2Test  {
+public class DBAppenderH2Test {
 
   LoggerContext lc;
   Logger logger;
@@ -44,13 +45,13 @@ public class DBAppenderH2Test  {
   DriverManagerConnectionSource connectionSource;
   DBAppenderH2TestFixture dbAppenderH2TestFixture;
   int diff = RandomUtil.getPositiveInt();
-  
+
   @Before
   public void setUp() throws SQLException {
     dbAppenderH2TestFixture = new DBAppenderH2TestFixture();
 
     dbAppenderH2TestFixture.setUp();
-    
+
     lc = new LoggerContext();
     lc.setName("default");
     logger = lc.getLogger("root");
@@ -61,16 +62,16 @@ public class DBAppenderH2Test  {
     connectionSource.setContext(lc);
     connectionSource.setDriverClass(DBAppenderH2TestFixture.H2_DRIVER_CLASS);
     connectionSource.setUrl(dbAppenderH2TestFixture.url);
-    System.out.println("cs.url="+dbAppenderH2TestFixture.url);
+    System.out.println("cs.url=" + dbAppenderH2TestFixture.url);
     connectionSource.setUser(dbAppenderH2TestFixture.user);
     connectionSource.setPassword(dbAppenderH2TestFixture.password);
-    
+
 
     connectionSource.start();
     appender.setConnectionSource(connectionSource);
     appender.start();
   }
-  
+
   @After
   public void tearDown() throws SQLException {
     logger = null;
@@ -85,9 +86,9 @@ public class DBAppenderH2Test  {
     ILoggingEvent event = createLoggingEvent();
 
     appender.append(event);
-    
+
     StatusPrinter.print(lc);
-    
+
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
     rs = stmt.executeQuery("SELECT * FROM logging_event");
@@ -106,11 +107,11 @@ public class DBAppenderH2Test  {
     } else {
       fail("No row was inserted in the database");
     }
-    
+
     rs.close();
     stmt.close();
   }
-  
+
   @Test
   public void testAppendThrowable() throws SQLException {
     ILoggingEvent event = createLoggingEvent();
@@ -121,29 +122,47 @@ public class DBAppenderH2Test  {
     rs.next();
     String expected = "java.lang.Exception: test Ex";
     String firstLine = rs.getString(3);
-    assertTrue("["+firstLine+"] does not match ["+expected+"]", firstLine.contains(expected));
-    
+    assertTrue("[" + firstLine + "] does not match [" + expected + "]", firstLine.contains(expected));
+
     int i = 0;
     while (rs.next()) {
       expected = event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString();
       String st = rs.getString(3);
-      assertTrue("["+st+"] does not match ["+expected+"]", st.contains(expected));
+      assertTrue("[" + st + "] does not match [" + expected + "]", st.contains(expected));
       i++;
     }
     assertTrue(i != 0);
-    
+
     rs.close();
     stmt.close();
   }
-  
+
+  @Test
+  public void withNullArgument() throws SQLException {
+    ILoggingEvent event = createLoggingEvent("Processing code {}; code type is {}; request date {}; record from date {}", new Object[] { 1, 2, new Date(), null });
+    appender.append(event);
+
+
+    Statement stmt = connectionSource.getConnection().createStatement();
+    ResultSet rs = null;
+    rs = stmt.executeQuery("SELECT * FROM logging_event");
+    if (rs.next()) {
+      assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
+      assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
+    }
+
+    StatusPrinter.print(lc);
+
+  }
+
   @Test
   public void testContextInfo() throws SQLException {
     lc.putProperty("testKey1", "testValue1");
-    MDC.put("k"+diff, "v"+diff);
+    MDC.put("k" + diff, "v" + diff);
     ILoggingEvent event = createLoggingEvent();
-    
+
     appender.append(event);
-    
+
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
     rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_PROPERTY WHERE EVENT_ID=1");
@@ -159,14 +178,15 @@ public class DBAppenderH2Test  {
     rs.close();
     stmt.close();
   }
-  
+
+
   @Test
   public void testAppendMultipleEvents() throws SQLException {
     for (int i = 0; i < 10; i++) {
       ILoggingEvent event = createLoggingEvent();
       appender.append(event);
     }
-    
+
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
     rs = stmt.executeQuery("SELECT * FROM logging_event");
@@ -175,15 +195,22 @@ public class DBAppenderH2Test  {
       count++;
     }
     assertEquals(10, count);
-    
+
     rs.close();
     stmt.close();
   }
-  
 
-  private ILoggingEvent createLoggingEvent() {
+
+  private ILoggingEvent createLoggingEvent(String msg, Object[] args) {
     ILoggingEvent le = new LoggingEvent(this.getClass().getName(), logger,
-        Level.DEBUG, "test message", new Exception("test Ex"), new Integer[] {diff});
+            Level.DEBUG, msg, new Exception("test Ex"), args);
     return le;
   }
+
+
+  private ILoggingEvent createLoggingEvent() {
+    return createLoggingEvent("test message", new Integer[]{diff});
+  }
+
+
 }
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 04bbcfa..57a55fb 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -35,6 +35,11 @@
     start method now correctly sets the state of the instance.
     </p>
 
+    <p>Corrected handling of null valued arguments by DBAppender. This
+    fixes <a
+    href="http://jira.qos.ch/browse/LBCLASSIC-239">LBCLASSIC-239</a>
+    reported by Artyom Kalita.</p>
+
     <hr width="80%" align="center" />
 
     <h3>December 22nd, 2010 - Release of version 0.9.27</h3>

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

Summary of changes:
 .../java/ch/qos/logback/classic/db/DBAppender.java |    9 ++-
 .../qos/logback/classic/db/DBAppenderH2Test.java   |   75 +++++++++++++------
 logback-site/src/site/pages/news.html              |    5 ++
 3 files changed, 63 insertions(+), 26 deletions(-)


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


More information about the logback-dev mailing list