[slf4j-dev] svn commit: r991 - in slf4j/trunk/jcl104-over-slf4j/src: main/java/org/apache/commons/logging/impl test/java/org/apache/commons/logging/impl

ceki at slf4j.org ceki at slf4j.org
Tue Feb 26 18:31:16 CET 2008


Author: ceki
Date: Tue Feb 26 18:31:16 2008
New Revision: 991

Added:
   slf4j/trunk/jcl104-over-slf4j/src/test/java/org/apache/commons/logging/impl/
   slf4j/trunk/jcl104-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java
Modified:
   slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLocationAwareLog.java
   slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLog.java

Log:
- SLF4JLog and SLF4JLocationAwareLog classes are now serializable. This corrects bug 71.

Note that the logger references in both classes now have to be transient. This is similar
to the support provided in the original JCL (see Log4jLogger Jdk14Logger classes)

http://bugzilla.slf4j.org/show_bug.cgi?id=71

Modified: slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLocationAwareLog.java
==============================================================================
--- slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLocationAwareLog.java	(original)
+++ slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLocationAwareLog.java	Tue Feb 26 18:31:16 2008
@@ -2,6 +2,8 @@
  
 package org.apache.commons.logging.impl;
 
+import java.io.Serializable;
+
 import org.apache.commons.logging.Log;
 import org.slf4j.Logger;
 import org.slf4j.spi.LocationAwareLogger;
@@ -14,9 +16,14 @@
  * 
  * @author Ceki Gülcü
  */
-public class SLF4JLocationAwareLog implements Log {
+public class SLF4JLocationAwareLog implements Log, Serializable {
+
+  private static final long serialVersionUID = -2379157579039314822L;
+  
+  // in both Log4jLogger and Jdk14Logger classes in the original JCL, the 
+  // logger instance is transient
+  private transient LocationAwareLogger logger;
 
-  private LocationAwareLogger logger;
   private static final String FQCN = SLF4JLocationAwareLog.class.getName();
   
   SLF4JLocationAwareLog(LocationAwareLogger logger) {

Modified: slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLog.java
==============================================================================
--- slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLog.java	(original)
+++ slf4j/trunk/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4JLog.java	Tue Feb 26 18:31:16 2008
@@ -2,6 +2,8 @@
 
 package org.apache.commons.logging.impl;
 
+import java.io.Serializable;
+
 import org.apache.commons.logging.Log;
 import org.slf4j.Logger;
 
@@ -14,9 +16,13 @@
  * 
  * @author Ceki Gülcü
  */
-public class SLF4JLog implements Log {
+public class SLF4JLog implements Log, Serializable {
+
+  private static final long serialVersionUID = 680728617011167209L;
 
-  private Logger logger;
+  // in both Log4jLogger and Jdk14Logger classes in the original JCL, the 
+  // logger instance is transient
+  private transient Logger logger;
 
   SLF4JLog(Logger logger) {
     this.logger = logger;

Added: slf4j/trunk/jcl104-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/jcl104-over-slf4j/src/test/java/org/apache/commons/logging/impl/SerializationTest.java	Tue Feb 26 18:31:16 2008
@@ -0,0 +1,41 @@
+package org.apache.commons.logging.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SerializationTest extends TestCase {
+
+  ObjectOutputStream oos;
+  
+  public SerializationTest(String name) {
+    super(name);
+  }
+
+  protected void setUp() throws Exception {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    oos = new ObjectOutputStream(baos);
+    super.setUp();
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    oos.close();
+  }
+
+  
+  public void testSmokeSimple() throws IOException {
+    Log log = LogFactory.getLog("testing");
+    oos.writeObject(log);
+  }
+  
+  public void testSmokeLocationAware() throws IOException {
+    SLF4JLocationAwareLog log = new SLF4JLocationAwareLog(null);
+    oos.writeObject(log);
+  }
+}



More information about the slf4j-dev mailing list