[logback-dev] svn commit: r2252 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/db main/java/ch/qos/logback/classic/log4j main/java/ch/qos/logback/classic/pattern main/java/ch/qos/logback/classic/spi test/java/ch/qos/logback/classic/corpus test/java/ch/qos/logback/classic/db test/java/ch/qos/logback/classic/spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Mar 20 16:35:21 CET 2009


Author: ceki
Date: Fri Mar 20 16:35:21 2009
New Revision: 2252

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/log4j/XMLLayout.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassOfCallerConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/FileOfCallerConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LineOfCallerConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MethodOfCallerConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/CallerData.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.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/spi/LoggingEventVO.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PubLoggingEventVO.java

Log:
As discussed in the dev mailing list, LoggingEvent now stores caller
data in the form of StackTraceElement[] instead of CallerData[].
CallerData class now only extracts caller data. It has no instance
variables.

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java	Fri Mar 20 16:35:21 2009
@@ -19,7 +19,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import ch.qos.logback.classic.spi.CallerData;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.StackTraceElementProxy;
 import ch.qos.logback.core.db.DBAppenderBase;
@@ -106,9 +105,9 @@
     stmt.setShort(6, DBHelper.computeReferenceMask(event));
   }
 
-  void bindCallerDataWithPreparedStatement(PreparedStatement stmt, CallerData[] callerDataArray)
+  void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray)
       throws SQLException {
-    CallerData callerData = callerDataArray[0];
+    StackTraceElement callerData = callerDataArray[0];
     if (callerData != null) {
       stmt.setString(7, callerData.getFileName());
       stmt.setString(8, callerData.getClassName());

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/log4j/XMLLayout.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/log4j/XMLLayout.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/log4j/XMLLayout.java	Fri Mar 20 16:35:21 2009
@@ -13,7 +13,6 @@
 import java.util.Set;
 import java.util.Map.Entry;
 
-import ch.qos.logback.classic.spi.CallerData;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.IThrowableProxy;
 import ch.qos.logback.classic.spi.StackTraceElementProxy;
@@ -137,9 +136,9 @@
     }
 
     if (locationInfo) {
-      CallerData[] callerDataArray = event.getCallerData();
+      StackTraceElement[] callerDataArray = event.getCallerData();
       if (callerDataArray != null && callerDataArray.length > 0) {
-        CallerData immediateCallerData = callerDataArray[0];
+        StackTraceElement immediateCallerData = callerDataArray[0];
         buf.append("  <log4j:locationInfo class=\"");
         buf.append(immediateCallerData.getClassName());
         buf.append("\"\r\n");

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java	Fri Mar 20 16:35:21 2009
@@ -110,7 +110,7 @@
       }
     }
 
-    CallerData[] cda = le.getCallerData();
+    StackTraceElement[] cda = le.getCallerData();
     if (cda != null && cda.length > 0) {
       int limit = depth < cda.length ? depth : cda.length;
 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassOfCallerConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassOfCallerConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassOfCallerConverter.java	Fri Mar 20 16:35:21 2009
@@ -16,7 +16,7 @@
 
   protected String getFullyQualifiedName(ILoggingEvent event) {
     
-    CallerData[] cda = event.getCallerData();
+    StackTraceElement[] cda = event.getCallerData();
     if (cda != null && cda.length > 0) {
       return cda[0].getClassName();
     } else {

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/FileOfCallerConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/FileOfCallerConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/FileOfCallerConverter.java	Fri Mar 20 16:35:21 2009
@@ -15,7 +15,7 @@
 public class FileOfCallerConverter extends ClassicConverter {
 
   public String convert(ILoggingEvent le) {
-    CallerData[] cda = le.getCallerData();
+    StackTraceElement[] cda = le.getCallerData();
     if (cda != null && cda.length > 0) {
       return cda[0].getFileName();
     } else {

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LineOfCallerConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LineOfCallerConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/LineOfCallerConverter.java	Fri Mar 20 16:35:21 2009
@@ -15,7 +15,7 @@
 public class LineOfCallerConverter extends ClassicConverter {
 
   public String convert(ILoggingEvent le) {
-    CallerData[] cda = le.getCallerData();
+    StackTraceElement[] cda = le.getCallerData();
     if (cda != null && cda.length > 0) {
       return Integer.toString(cda[0].getLineNumber());
     } else {

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MethodOfCallerConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MethodOfCallerConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MethodOfCallerConverter.java	Fri Mar 20 16:35:21 2009
@@ -15,7 +15,7 @@
 public class MethodOfCallerConverter extends ClassicConverter {
 
   public String convert(ILoggingEvent le) {
-    CallerData[] cda = le.getCallerData();
+    StackTraceElement[] cda = le.getCallerData();
     if (cda != null && cda.length > 0) {
       return cda[0].getMethodName();
     } else {

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/CallerData.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/CallerData.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/CallerData.java	Fri Mar 20 16:35:21 2009
@@ -12,13 +12,13 @@
 import ch.qos.logback.core.CoreConstants;
 
 /**
- * The internal representation of caller location information.
+ * This class computes caller data returning the result in the form
+ * of a StackTraceElement array.
  * 
  * @author Ceki G&uuml;lc&uuml;
  */
-public class CallerData implements java.io.Serializable {
+public class CallerData {
 
-  private static final long serialVersionUID = 2473626903716082403L;
 
   /**
    * When caller information is not available this constant is used for file
@@ -40,58 +40,21 @@
   /**
    * This value is returned in case no caller data could be extracted.
    */
-  public static CallerData[] EMPTY_CALLER_DATA_ARRAY = new CallerData[0];
+  public static StackTraceElement[] EMPTY_CALLER_DATA_ARRAY = new StackTraceElement[0];
 
-  /**
-   * Caller's line number.
-   */
-  int lineNumber;
-
-  /**
-   * Caller's file name.
-   */
-  String fileName;
-
-  /**
-   * Caller's fully qualified class name.
-   */
-  String className;
-
-  /**
-   * Caller's method name.
-   */
-  String methodName;
-
-  boolean nativeMethod = false;
-
-  public CallerData(String fileName, String className, String methodName,
-      int lineNumber) {
-    this.fileName = fileName;
-    this.className = className;
-    this.methodName = methodName;
-    this.lineNumber = lineNumber;
-  }
-
-  public CallerData(StackTraceElement ste) {
-    className = ste.getClassName();
-    fileName = ste.getFileName();
-    methodName = ste.getMethodName();
-    lineNumber = ste.getLineNumber();
-    nativeMethod = ste.isNativeMethod();
-  }
 
   /**
    * Extract caller data information as an array based on a Throwable passed as
    * parameter
    */
-  public static CallerData[] extract(Throwable t, String fqnOfInvokingClass,
-      final int maxDepth) {
+  public static StackTraceElement[] extract(Throwable t,
+      String fqnOfInvokingClass, final int maxDepth) {
     if (t == null) {
       return null;
     }
 
     StackTraceElement[] steArray = t.getStackTrace();
-    CallerData[] callerDataArray;
+    StackTraceElement[] callerDataArray;
 
     int found = LINE_NA;
     for (int i = 0; i < steArray.length; i++) {
@@ -114,9 +77,9 @@
     int availableDepth = steArray.length - found;
     int desiredDepth = maxDepth < (availableDepth) ? maxDepth : availableDepth;
 
-    callerDataArray = new CallerData[desiredDepth];
+    callerDataArray = new StackTraceElement[desiredDepth];
     for (int i = 0; i < desiredDepth; i++) {
-      callerDataArray[i] = new CallerData(steArray[found+i]);
+      callerDataArray[i] = steArray[found + i];
     }
     return callerDataArray;
   }
@@ -134,95 +97,4 @@
     }
   }
 
-  public boolean equals(Object o) {
-    // LogLog.info("equals called");
-    if (this == o) {
-      return true;
-    }
-
-    if (!(o instanceof CallerData)) {
-      // LogLog.info("inequality point 1");
-      return false;
-    }
-
-    CallerData r = (CallerData) o;
-
-    if (!getClassName().equals(r.getClassName())) {
-      // LogLog.info("inequality point 2");
-      return false;
-    }
-
-    if (!getFileName().equals(r.getFileName())) {
-      // LogLog.info("inequality point 3");
-      return false;
-    }
-
-    if (!getMethodName().equals(r.getMethodName())) {
-      // LogLog.info("inequality point 4");
-      return false;
-    }
-
-    if (!(lineNumber == r.lineNumber)) {
-      // LogLog.info("inequality point 5");
-      return false;
-    }
-
-    return true;
-  }
-
-  /**
-   * Return the fully qualified class name of the caller making the logging
-   * request.
-   */
-  public String getClassName() {
-    return className;
-  }
-
-  /**
-   * Return the file name of the caller.
-   * 
-   * <p> This information is not always available.
-   */
-  public String getFileName() {
-    return fileName;
-  }
-
-  /**
-   * Returns the line number of the caller.
-   * 
-   * <p> This information is not always available.
-   */
-  public int getLineNumber() {
-    return lineNumber;
-  }
-
-  /**
-   * Returns the method name of the caller.
-   */
-  public String getMethodName() {
-    return methodName;
-  }
-
-  public String toString() {
-    StringBuffer buf = new StringBuffer();
-    buf.append(getClassName());
-    buf.append('.');
-    buf.append(getMethodName());
-    buf.append('(');
-    if (isNativeMethod()) {
-      buf.append("Native Method");
-    } else if (getFileName() == null) {
-      buf.append("Unknown Source");
-    } else {
-      buf.append(getFileName());
-      buf.append(':');
-      buf.append(getLineNumber());
-    }
-    buf.append(')');
-    return buf.toString();
-  }
-
-  public boolean isNativeMethod() {
-    return nativeMethod;
-  }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java	Fri Mar 20 16:35:21 2009
@@ -31,14 +31,14 @@
   public IThrowableProxy getThrowableProxy();
 
   /**
-   * Return {@link CallerData} associated with this event. Note that calling
+   * Return caller data associated with this event. Note that calling
    * this event may trigger the computation of caller data.
    * 
-   * @return the CallerData associated with this event.
+   * @return the caller data associated with this event.
    * 
    * @see #hasCallerData()
    */
-  public CallerData[] getCallerData();
+  public StackTraceElement[] getCallerData();
 
   /**
    * If this event has caller data, then true is returned. Otherwise the

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	Fri Mar 20 16:35:21 2009
@@ -75,7 +75,7 @@
 
   private ThrowableProxy throwableProxy;
 
-  private CallerData[] callerDataArray;
+  private StackTraceElement[] callerDataArray;
 
   private Marker marker;
 
@@ -241,7 +241,7 @@
    * <p> Note that after serialization it is impossible to correctly extract
    * caller information. </p>
    */
-  public CallerData[] getCallerData() {
+  public StackTraceElement[] getCallerData() {
     if (callerDataArray == null) {
       callerDataArray = CallerData.extract(new Throwable(), fqnOfLoggerClass, loggerContext.getMaxCallerDataDepth());
     }
@@ -252,7 +252,7 @@
     return (callerDataArray != null);
   }
 
-  public void setCallerData(CallerData[] callerDataArray) {
+  public void setCallerData(StackTraceElement[] callerDataArray) {
     this.callerDataArray = callerDataArray;
   }
 

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	Fri Mar 20 16:35:21 2009
@@ -41,7 +41,7 @@
   private transient Object[] argumentArray;
 
   private ThrowableProxyVO throwableProxy;
-  private CallerData[] callerDataArray;
+  private StackTraceElement[] callerDataArray;
   private Marker marker;
   private Map<String, String> mdcPropertyMap;
   private long timeStamp;
@@ -103,7 +103,7 @@
     return throwableProxy;
   }
 
-  public CallerData[] getCallerData() {
+  public StackTraceElement[] getCallerData() {
     return callerDataArray;
   }
 

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java	Fri Mar 20 16:35:21 2009
@@ -14,7 +14,6 @@
 
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.CallerData;
 import ch.qos.logback.classic.spi.ClassPackagingData;
 import ch.qos.logback.classic.spi.LoggerContextVO;
 import ch.qos.logback.classic.spi.StackTraceElementProxy;
@@ -184,15 +183,15 @@
     }
   }
 
-  public CallerData[] getRandomCallerData(int depth, String loggerName) {
-    CallerData[] cda = new CallerData[depth];
-    CallerData cd = new CallerData(extractLastPart(loggerName), loggerName,
-        getRandomJavaIdentifier(), 0);
+  public StackTraceElement[] getRandomCallerData(int depth, String loggerName) {
+    StackTraceElement[] cda = new StackTraceElement[depth];
+    StackTraceElement cd = new StackTraceElement(loggerName,
+        getRandomJavaIdentifier(), extractLastPart(loggerName), 0);
     cda[0] = cd;
     for (int i = 1; i < depth; i++) {
       String ln = getRandomLoggerNameFromPool(loggerNamePool);
-      cda[i] = new CallerData(extractLastPart(ln), ln,
-          getRandomJavaIdentifier(), i * 10);
+      cda[i] = new StackTraceElement(ln, getRandomJavaIdentifier(),
+          extractLastPart(ln), i * 10);
     }
     return cda;
   }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java	Fri Mar 20 16:35:21 2009
@@ -15,7 +15,6 @@
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.CallerData;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
@@ -77,7 +76,7 @@
       assertEquals(event.getLevel().toString(), rs.getString(4));
       assertEquals(event.getThreadName(), rs.getString(5));
       assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(6));
-      CallerData callerData = event.getCallerData()[0];
+      StackTraceElement callerData = event.getCallerData()[0];
       assertEquals(callerData.getFileName(), rs.getString(7));
       assertEquals(callerData.getClassName(), rs.getString(8));
       assertEquals(callerData.getMethodName(), rs.getString(9));

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java	Fri Mar 20 16:35:21 2009
@@ -14,7 +14,7 @@
     Throwable t = new Throwable();
     StackTraceElement[] steArray = t.getStackTrace();
     
-    CallerData[] cda = CallerData.extract(t, CallerDataTest.class.getName(), 50);
+    StackTraceElement[] cda = CallerData.extract(t, CallerDataTest.class.getName(), 50);
     assertNotNull(cda);
     assertTrue(cda.length > 0);
     assertEquals(steArray.length - 1, cda.length);
@@ -27,7 +27,7 @@
    */
   @Test
   public void testDeferredProcessing() {
-    CallerData[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo", 10);
+    StackTraceElement[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo", 10);
     assertNotNull(cda);
     assertEquals(0, cda.length);
   }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PubLoggingEventVO.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PubLoggingEventVO.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PubLoggingEventVO.java	Fri Mar 20 16:35:21 2009
@@ -46,7 +46,7 @@
   public Object[] argumentArray;
 
   public IThrowableProxy throwableProxy;
-  public CallerData[] callerDataArray;
+  public StackTraceElement[] callerDataArray;
   public Marker marker;
   public Map<String, String> mdcPropertyMap;
   public long timeStamp;
@@ -95,7 +95,7 @@
     return throwableProxy;
   }
 
-  public CallerData[] getCallerData() {
+  public StackTraceElement[] getCallerData() {
     return callerDataArray;
   }
 


More information about the logback-dev mailing list