[LOGBack-dev] svn commit: r515 - in logback/trunk/logback-classic: doc/designDiscussion src/main/java/ch/qos/logback/classic src/main/java/ch/qos/logback/classic/spi src/main/java/ch/qos/logback/classic/util src/test/java/ch/qos/logback/classic src/test/java/ch/qos/logback/classic/net

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Sep 6 15:38:42 CEST 2006


Author: seb
Date: Wed Sep  6 15:38:42 2006
New Revision: 515

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextSer.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextView.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerSer.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerView.java
Modified:
   logback/trunk/logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java
   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/SocketMin.java

Log:
Initial Commit: design change - work in progress.
- Added two interfaces LoggerView and LoggerContextView. 
- Logger, LoggerSer and LoggerContext, LoggerContextSer implements these interfaces, respectively.
- LoggerSer and LoggerContextSer are the serialized versions of Logger and LoggerContext.
- Committing a few more classes that were impacted by these changes.
- Updated test classes.

Modified: logback/trunk/logback-classic/doc/designDiscussion/LoggingEvent Serialization.odt
==============================================================================
Binary files. No diff available.

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java	Wed Sep  6 15:38:42 2006
@@ -17,7 +17,6 @@
 import java.util.List;
 
 import org.slf4j.Marker;
-import org.slf4j.impl.MessageFormatter;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.Appender;
@@ -26,7 +25,7 @@
 import ch.qos.logback.core.spi.AppenderAttachableImpl;
 
 
-public final class Logger implements org.slf4j.Logger, AppenderAttachable, Serializable {
+public final class Logger implements org.slf4j.Logger, LoggerView, AppenderAttachable, Serializable {
 
   /**
 	 * 
@@ -689,7 +688,15 @@
    * Return the context for this logger.
    * @return
    */
-	public LoggerContext getLoggerContext() {
+	public LoggerContextView getLoggerContext() {
 		return loggerContext;
 	}
+	
+	public LoggerSer getLoggerSer() {
+		LoggerSer loggerSer = new LoggerSer();
+		loggerSer.level = level;
+		loggerSer.name = name;
+		loggerSer.loggerContext = loggerContext.getLoggerContextSer();
+		return loggerSer;
+	}
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	Wed Sep  6 15:38:42 2006
@@ -23,7 +23,7 @@
 /**
  * @author ceki
  */
-public class LoggerContext extends ContextBase implements ILoggerFactory {
+public class LoggerContext extends ContextBase implements ILoggerFactory, LoggerContextView {
 
 	public static final String ROOT_NAME = "root";
 	
@@ -114,4 +114,11 @@
 	        "No appenders present in context ["+ getName() +"] for logger [" + logger.getName() + "].", logger));
   	 }
   }
+  
+  public LoggerContextSer getLoggerContextSer() {
+  	LoggerContextSer loggerContextSer = new LoggerContextSer();
+  	loggerContextSer.name = this.getName();
+  	loggerContextSer.propertyMap = this.getPropertyMap();
+  	return loggerContextSer;
+  }
 }

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextSer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextSer.java	Wed Sep  6 15:38:42 2006
@@ -0,0 +1,40 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, 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.classic;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * The object used to contain the LoggerContext informations once the
+ * serialization has taken place.
+ * 
+ * @author Sébastien Pennec
+ */
+public class LoggerContextSer implements LoggerContextView, Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 6615558506849441711L;
+	
+	
+	String name;
+	Map<String, String> propertyMap;
+	
+	public String getName() {
+		return name;
+	}
+
+	public Map<String, String> getPropertyMap() {
+		return propertyMap;
+	}
+
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextView.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContextView.java	Wed Sep  6 15:38:42 2006
@@ -0,0 +1,9 @@
+package ch.qos.logback.classic;
+
+import java.util.Map;
+
+public interface LoggerContextView {
+
+	public String getName();
+	public Map<String, String> getPropertyMap();
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerSer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerSer.java	Wed Sep  6 15:38:42 2006
@@ -0,0 +1,46 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, 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.classic;
+
+import java.io.Serializable;
+
+/**
+ * The object used to contain the LoggerContext informations once the
+ * serialization has taken place.
+ * 
+ * @author S&eacute;bastien Pennec
+ */
+public class LoggerSer implements LoggerView, Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 5323186084164784257L;
+
+	Level level;
+	LoggerContextView loggerContext;
+	String name;
+
+	public Level getLevel() {
+		return level;
+	}
+
+	public LoggerContextView getLoggerContext() {
+		return loggerContext;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public LoggerSer getLoggerSer() {
+		return this;
+	}
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerView.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerView.java	Wed Sep  6 15:38:42 2006
@@ -0,0 +1,28 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, 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.classic;
+
+/**
+ * An interface that allows Logger objects and LoggerSer objects to be used the
+ * same way be client of the LoggingEvent object.
+ * 
+ * @author S&eacute;bastien Pennec
+ */
+public interface LoggerView {
+
+	public String getName();
+
+	public Level getLevel();
+
+	public LoggerContextView getLoggerContext();
+
+	public LoggerSer getLoggerSer();
+}

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java	Wed Sep  6 15:38:42 2006
@@ -16,11 +16,11 @@
 import java.io.Serializable;
 
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 import org.slf4j.impl.MessageFormatter;
 
 import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerView;
 
 /**
  * The internal representation of logging events. When an affirmative decision
@@ -80,9 +80,9 @@
 
 	private Object[] argumentArray;
 
-	private transient Logger logger;
+	private transient LoggerView logger;
 
-  private transient ThrowableInformation throwableInfo;
+	private transient ThrowableInformation throwableInfo;
 
 	private transient CallerData[] callerDataArray;
 
@@ -100,7 +100,7 @@
 	public LoggingEvent(String fqcn, Logger logger, Level level, String message,
 			Throwable throwable, Object[] argArray) {
 		this.fqnOfLoggerClass = fqcn;
-		this.logger = logger;
+		this.logger = (ch.qos.logback.classic.Logger)logger;
 		this.level = level;
 		this.message = message;
 
@@ -179,11 +179,11 @@
 		this.getThreadName();
 	}
 
-	public Logger getLogger() {
+	public LoggerView getLogger() {
 		return logger;
 	}
 
-	public void setLogger(Logger logger) {
+	public void setLogger(LoggerView logger) {
 		this.logger = logger;
 	}
 
@@ -266,15 +266,16 @@
 
 	private void writeObject(ObjectOutputStream out) throws IOException {
 		out.defaultWriteObject();
-		out.writeObject(logger.getName());
+		out.writeObject(logger.getLoggerSer());
 		out.writeInt(level.levelInt);
 	}
 
 	private void readObject(ObjectInputStream in) throws IOException,
 			ClassNotFoundException {
 		in.defaultReadObject();
-		String loggerName = (String) in.readObject();
-		logger = LoggerFactory.getLogger(loggerName);
+		//String loggerName = (String) in.readObject();
+		//logger = LoggerFactory.getLogger(loggerName);
+		logger = (LoggerView)in.readObject();
 		int levelInt = in.readInt();
 		level = Level.toLevel(levelInt);
 	}

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/LoggerStatusPrinter.java	Wed Sep  6 15:38:42 2006
@@ -12,7 +12,7 @@
 	
 	public static void printStatusInDefaultContext() {
 		Logger logger = (Logger)LoggerFactory.getLogger(LoggerStatusPrinter.class);
-		LoggerContext lc = logger.getLoggerContext();
+		LoggerContext lc = (LoggerContext)logger.getLoggerContext();
 		StatusManager sm = lc.getStatusManager();
     StatusPrinter.print(sm);
 	}

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java	Wed Sep  6 15:38:42 2006
@@ -13,7 +13,6 @@
 
 import org.slf4j.LoggerFactory;
 
-import ch.qos.logback.BasicConfigurator;
 import ch.qos.logback.core.appender.ListAppender;
 import ch.qos.logback.core.util.StatusPrinter;
 
@@ -60,7 +59,7 @@
   
   public void testRootLogger() {
   	Logger logger = (Logger)LoggerFactory.getLogger(LoggerContext.ROOT_NAME);
-  	LoggerContext lc = logger.getLoggerContext();
+  	LoggerContext lc = (LoggerContext)logger.getLoggerContext();
 		
   	assertNotNull("Returned logger is null", logger);
   	assertEquals("Return logger isn't named root", logger.getName(), LoggerContext.ROOT_NAME);

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java	Wed Sep  6 15:38:42 2006
@@ -16,6 +16,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import ch.qos.logback.classic.spi.LoggingEvent;
+
 /**
  * 
  * 
@@ -23,20 +25,13 @@
  */
 public class MockSocketServer extends Thread {
 
-	static final String LOGGINGEVENT = "LoggingEvent";
-	static final String LOGGINGEVENT2 = "LoggingEvent2";
-	static final String MINIMALEXT = "MinimalExt";
-	static final String MINIMALSER = "MinimalSer";
-
 	static final int PORT = 4560;
 
 	final int loopLen;
 
-	List<String> msgList = new ArrayList<String>();
+	List<LoggingEvent> loggingEventList = new ArrayList<LoggingEvent>();
 	boolean finished = false;
 
-	String className = LOGGINGEVENT;
-
 	MockSocketServer(int loopLen) {
 		super();
 		this.loopLen = loopLen;
@@ -45,7 +40,8 @@
 	@Override
 	public void run() {
 		ObjectInputStream ois;
-		Object readObject;
+		//Object readObject;
+		LoggingEvent event;
 		try {
 			//System.out.println("Listening on port " + PORT);
 			ServerSocket serverSocket = new ServerSocket(PORT);
@@ -55,8 +51,10 @@
 			ois = new ObjectInputStream(new BufferedInputStream(socket
 					.getInputStream()));
 			for (int i = 0; i < loopLen; i++) {
-				readObject = ois.readObject();
-				msgList.add(readObject.toString());
+				event = (LoggingEvent)ois.readObject();
+//				System.out.println("* LoggerName:" + event.getLogger().getName());
+//				System.out.println("* Context Name: " + event.getLogger().getLoggerContext().getName());
+				loggingEventList.add(event);
 			}
 			ois.close();
 			serverSocket.close();

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	Wed Sep  6 15:38:42 2006
@@ -14,28 +14,25 @@
 public class SerializationPerfsTest extends TestCase {
 
 	ObjectOutputStream oos;
-	MockSocketServer mockServer;
 
 	int loopNumber = 10000;
 	int resetFrequency = 100;
-	int pauseFrequency = 500;
+	int pauseFrequency = 200;
 	long pauseLengthInMillis = 20;
-	
+
 	/**
+	 * <p>
 	 * Run the test with a MockSocketServer or with a NOPOutputStream
-	 */
-	boolean runWithMockServer = true;
-	/**
+	 * </p>
 	 * <p>
-	 * Run with external mock can be done using the
-	 * ExternalMockSocketServer. It needs to be launched
-	 * from a separate JVM. The ExternalMockSocketServer does not
-	 * consume the events but passes through the available bytes
-	 * that it is recieving.
+	 * Run with external mock can be done using the ExternalMockSocketServer. It
+	 * needs to be launched from a separate JVM. The ExternalMockSocketServer does
+	 * not consume the events but passes through the available bytes that it is
+	 * recieving.
 	 * </p>
 	 * <p>
-	 * For example, with 4 test methods,
-	 * you can launch the ExternalMockSocketServer this way:
+	 * For example, with 4 test methods, you can launch the
+	 * ExternalMockSocketServer this way:
 	 * </p>
 	 * <p>
 	 * <code>java ch.qos.logback.classic.net.ExternalMockSocketServer 4</code>
@@ -55,13 +52,6 @@
 	 *   | LoggEvent Ext  | 10000 |  9641    |           |
 	 *   | LoggEvent Ser  | 10000 | 25729    |           |
 	 * 
-	 * Internal MockServer: 
-	 * 	 |                |  Runs | Avg time | Data sent |
-	 *   | MinimalObj Ext | 10000 |  62040   |           |
-	 *   | MinimalObj Ser | 10000 |  76237   |           |
-	 *   | LoggEvent Ext  | 10000 | 122714   |           |
-	 *   | LoggEvent Ser  | 10000 | 121711   |           |
-	 * 
 	 * External MockServer with 45 letters-long message: 
 	 * 	 |                |  Runs | Avg time | Data sent |
 	 *   | MinimalObj Ext | 10000 |  70240   | 1171384   |
@@ -90,13 +80,9 @@
 
 	public void setUp() throws Exception {
 		super.setUp();
-		if (runWithMockServer) {
-			if (!runWithExternalMockServer) {
-				mockServer = new MockSocketServer(loopNumber * 2);
-				mockServer.start();
-			}
+		if (runWithExternalMockServer) {
 			oos = new ObjectOutputStream(new Socket("localhost",
-					MockSocketServer.PORT).getOutputStream());
+					ExternalMockSocketServer.PORT).getOutputStream());
 		} else {
 			oos = new ObjectOutputStream(new NOPOutputStream());
 		}
@@ -106,20 +92,19 @@
 		super.tearDown();
 		oos.close();
 		oos = null;
-		mockServer = null;
 	}
 
 	public void runPerfTest(Builder builder, String label) throws Exception {
-		//long time1 = System.nanoTime();
+		// long time1 = System.nanoTime();
+
+		// Object builtObject = builder.build(1);
 
-		Object builtObject = builder.build(1);
-		
 		// first run for just in time compiler
 		int resetCounter = 0;
 		int pauseCounter = 0;
 		for (int i = 0; i < loopNumber; i++) {
 			try {
-				oos.writeObject(builtObject);
+				oos.writeObject(builder.build(i));
 				oos.flush();
 				if (++resetCounter >= resetFrequency) {
 					oos.reset();
@@ -129,6 +114,7 @@
 					Thread.sleep(pauseLengthInMillis);
 					pauseCounter = 0;
 				}
+
 			} catch (IOException ex) {
 				fail(ex.getMessage());
 			}
@@ -136,15 +122,15 @@
 
 		// second run
 		Long t1;
-		Long t2 ;
+		Long t2;
 		Long total = 0L;
 		resetCounter = 0;
 		pauseCounter = 0;
-		//System.out.println("Beginning mesured run");
+		// System.out.println("Beginning mesured run");
 		for (int i = 0; i < loopNumber; i++) {
 			try {
 				t1 = System.nanoTime();
-				oos.writeObject(builtObject);
+				oos.writeObject(builder.build(i));
 				oos.flush();
 				t2 = System.nanoTime();
 				total += (t2 - t1);
@@ -163,13 +149,9 @@
 		System.out.println(label + " : average time = " + total / loopNumber
 				+ " after " + loopNumber + " writes.");
 
-		if (runWithMockServer && !runWithExternalMockServer) {
-			mockServer.join(1000);
-			assertTrue(mockServer.finished);
-		}
-		
-		//long time2 = System.nanoTime();
-		//System.out.println("********* -> Time needed to run the test method: " + Long.toString(time2-time1));
+		// long time2 = System.nanoTime();
+		// System.out.println("********* -> Time needed to run the test method: " +
+		// Long.toString(time2-time1));
 	}
 
 	public void testWithMinimalExternalization() throws Exception {

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	Wed Sep  6 15:38:42 2006
@@ -1,8 +1,11 @@
 package ch.qos.logback.classic.net;
 
+import java.util.Map;
+
 import junit.framework.TestCase;
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggingEvent;
 
 public class SocketAppenderTest extends TestCase {
 
@@ -22,6 +25,8 @@
 		
 		// client configuration
 		LoggerContext lc = new LoggerContext();
+		lc.setName("test");
+		lc.getPropertyMap().put("testKey", "testValue");
 		Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
 		SocketAppender socketAppender = new SocketAppender();
 		socketAppender.setContext(lc);
@@ -30,7 +35,7 @@
 		socketAppender.setRemoteHost("localhost");
 		root.addAppender(socketAppender);
 		socketAppender.start();
-		
+				
 		Logger logger = lc.getLogger(LoggerContext.ROOT_NAME);
 		logger.debug("test");
 
@@ -38,7 +43,11 @@
     // finish much sooner than that.		
 		mockServer.join(2000);
 		assertTrue(mockServer.finished);
-		assertTrue(mockServer.msgList.get(0).startsWith("ch.qos.logback.classic.spi.LoggingEvent@"));
-		
+		assertEquals(1, mockServer.loggingEventList.size());
+		LoggingEvent remoteEvent = mockServer.loggingEventList.get(0);
+		assertEquals("test", remoteEvent.getLogger().getLoggerContext().getName());
+		assertEquals("root", remoteEvent.getLogger().getName());
+		Map<String, String> props = remoteEvent.getLogger().getLoggerContext().getPropertyMap();
+		assertEquals("testValue", props.get("testKey"));
 	}
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketMin.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketMin.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketMin.java	Wed Sep  6 15:38:42 2006
@@ -50,7 +50,7 @@
 
 	static void init(String host, String portStr) {
 		Logger root = (Logger) LoggerFactory.getLogger(LoggerContext.ROOT_NAME);
-		BasicConfigurator.configure(root.getLoggerContext());
+		BasicConfigurator.configure((LoggerContext)root.getLoggerContext());
 		try {
 			int port = Integer.parseInt(portStr);
 			logger.info("Creating socket appender (" + host + "," + port + ").");



More information about the logback-dev mailing list