[logback-dev] svn commit: r2433 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/spi test/java/ch/qos/logback/classic/net

noreply.ceki at qos.ch noreply.ceki at qos.ch
Sun Aug 9 20:44:14 CEST 2009


Author: ceki
Date: Sun Aug  9 20:44:14 2009
New Revision: 2433

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventVO.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java

Log:
- Add caller data in LoggingEventVO to fix LBCLASSIC-145

  Implemented as 
  
  if(le.hasCallerData()) {
    ledo.callerData = le.getCallerData();
  }
  
  as (correctly) suggested by Joern Huxhorn
- added  test case as appropriate

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventVO.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventVO.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEventVO.java	Sun Aug  9 20:44:14 2009
@@ -58,6 +58,11 @@
     ledo.mdcPropertyMap = le.getMDCPropertyMap();
     ledo.timeStamp = le.getTimeStamp();
     ledo.throwableProxy = ThrowableProxyVO.build(le.getThrowableProxy());
+    // add caller data only if it is there already
+    // fixes http://jira.qos.ch/browse/LBCLASSIC-145
+    if(le.hasCallerData()) {
+      ledo.callerDataArray = le.getCallerData();
+    }
     return ledo;
   }
 

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java	Sun Aug  9 20:44:14 2009
@@ -11,6 +11,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Map;
@@ -39,7 +40,7 @@
   LoggerContext serverLC = new LoggerContext();
   ListAppender<ILoggingEvent> la = new ListAppender<ILoggingEvent>();
   SocketAppender socketAppender = new SocketAppender();
-
+  private boolean includeCallerData = false;
   private SimpleSocketServer simpleSocketServer;
 
   @Test
@@ -68,6 +69,7 @@
     assertEquals(1, la.list.size());
 
     ILoggingEvent remoteEvent = la.list.get(0);
+    assertNull(remoteEvent.getCallerData());
     assertEquals("test msg", remoteEvent.getMessage());
     assertEquals(Level.DEBUG, remoteEvent.getLevel());
   }
@@ -95,6 +97,7 @@
 
     LoggerContextVO loggerContextRemoteView = remoteEvent
         .getLoggerContextVO();
+    assertNull(remoteEvent.getCallerData());
     assertNotNull(loggerContextRemoteView);
     assertEquals("test", loggerContextRemoteView.getName());
     Map<String, String> props = loggerContextRemoteView.getPropertyMap();
@@ -122,8 +125,31 @@
     ILoggingEvent remoteEvent = la.list.get(0);
     Map<String, String> MDCPropertyMap = remoteEvent.getMDCPropertyMap();
     assertEquals("testValue", MDCPropertyMap.get("key"));
+    assertNull(remoteEvent.getCallerData());
   }
 
+  // test http://jira.qos.ch/browse/LBCLASSIC-145
+  @Test
+  public void withCallerData() throws InterruptedException {
+    includeCallerData = true;
+    fireServer();
+    waitForServerToStart();
+    configureClient();
+
+    Logger logger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
+    logger.debug("test msg");
+
+    Thread.sleep(SLEEP_AFTER_LOG);
+    simpleSocketServer.close();
+    simpleSocketServer.join(JOIN_OR_WAIT_TIMEOUT);
+    assertTrue(simpleSocketServer.isClosed());
+    ListAppender<ILoggingEvent> la = getListAppender();
+    assertEquals(1, la.list.size());
+
+    ILoggingEvent remoteEvent = la.list.get(0);
+    assertNotNull(remoteEvent.getCallerData());
+  }
+  
   @Test
   public void messageWithMarker() throws InterruptedException {
     fireServer();
@@ -234,6 +260,7 @@
     socketAppender.setName("socket");
     socketAppender.setPort(port);
     socketAppender.setRemoteHost("localhost");
+    socketAppender.setIncludeCallerData(includeCallerData);
     root.addAppender(socketAppender);
     socketAppender.start();
   }


More information about the logback-dev mailing list