You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2004/09/07 19:16:05 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/chainsaw/filter FilterModel.java
ceki 2004/09/07 10:16:05
Modified: src/java/org/apache/log4j/xml UtilLoggingXMLDecoder.java
XMLDecoder.java XMLLayout.java
src/java/org/apache/log4j/spi LoggingEventFieldResolver.java
LoggingEvent.java
src/java/org/apache/log4j/db DBReceiverJob.java
DBAppender2.java DBAppender.java
src/java/org/apache/log4j/chainsaw
ChainsawCyclicBufferTableModel.java
tests/src/java/org/apache/log4j/performance Loop.java
tests/src/java/org/apache/log4j/db FullCycleDBTest.java
src/java/org/apache/log4j HTMLLayout.java
src/java/org/apache/log4j/lf5 LF5Appender.java
src/java/org/apache/log4j/pattern
MethodLocationPatternConverter.java
FileLocationPatternConverter.java
LineLocationPatternConverter.java
FullLocationPatternConverter.java
tests build.xml
src/java/org/apache/log4j/chainsaw/layout
LayoutEditorPane.java EventDetailLayout.java
src/java/org/apache/log4j/varia LogFilePatternReceiver.java
src/java/org/apache/log4j/chainsaw/filter FilterModel.java
Added: src/java/org/apache/log4j/spi/location LocationInfo.java
LegacyExtractor.java
tests/src/java/org/apache/log4j/spi/location
LocationInfoTest.java
Removed: src/java/org/apache/log4j/spi LocationInfo.java
Log:
- Created a new o.a.l.spi.location package
- Moved o.a.l.spi.LocationInfo class to o.a.l.spi.location.LocationInfo
- Updated many classes to reflect the name change
- The location info extraction code has beed factored out to its own class. New and improved extraction strategies to follow.
- Previously "transient" fields in LocationInfo are now serialized.
Revision Changes Path
1.18 +1 -1 logging-log4j/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
Index: UtilLoggingXMLDecoder.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- UtilLoggingXMLDecoder.java 9 Jul 2004 14:41:06 -0000 1.17
+++ UtilLoggingXMLDecoder.java 7 Sep 2004 17:16:01 -0000 1.18
@@ -38,9 +38,9 @@
import org.apache.log4j.Logger;
import org.apache.log4j.UtilLoggingLevel;
import org.apache.log4j.spi.Decoder;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import org.apache.log4j.spi.location.LocationInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
1.23 +1 -1 logging-log4j/src/java/org/apache/log4j/xml/XMLDecoder.java
Index: XMLDecoder.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/xml/XMLDecoder.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- XMLDecoder.java 8 Aug 2004 23:28:11 -0000 1.22
+++ XMLDecoder.java 7 Sep 2004 17:16:01 -0000 1.23
@@ -36,9 +36,9 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.Decoder;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import org.apache.log4j.spi.location.LocationInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
1.30 +1 -1 logging-log4j/src/java/org/apache/log4j/xml/XMLLayout.java
Index: XMLLayout.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/xml/XMLLayout.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- XMLLayout.java 3 Jun 2004 21:57:09 -0000 1.29
+++ XMLLayout.java 7 Sep 2004 17:16:01 -0000 1.30
@@ -19,8 +19,8 @@
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.Transform;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
import java.io.IOException;
import java.io.Writer;
1.9 +2 -0 logging-log4j/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java
Index: LoggingEventFieldResolver.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEventFieldResolver.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- LoggingEventFieldResolver.java 2 Jul 2004 17:14:38 -0000 1.8
+++ LoggingEventFieldResolver.java 7 Sep 2004 17:16:02 -0000 1.9
@@ -20,6 +20,8 @@
import java.util.List;
import java.util.StringTokenizer;
+import org.apache.log4j.spi.location.LocationInfo;
+
/**
1.64 +2 -1 logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- LoggingEvent.java 17 May 2004 16:58:29 -0000 1.63
+++ LoggingEvent.java 7 Sep 2004 17:16:02 -0000 1.64
@@ -30,6 +30,7 @@
import org.apache.log4j.NDC;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.location.LocationInfo;
// Contributors: Nelson Minar <ne...@monkey.org>
@@ -54,7 +55,7 @@
* <p>Moreover, in the absence of certain fields, receivers must set the
* values of null fields to a default non-null value. For example, in the
* absence of the locationInfo data, the locationInfo field should be
- * set to {@link org.apache.log4j.spi.LocationInfo#NA_LOCATION_INFO
+ * set to {@link org.apache.log4j.spi.location.LocationInfo#NA_LOCATION_INFO
* LocationInfo.NA_LOCATION_INFO}.
*
*
1.1 logging-log4j/src/java/org/apache/log4j/spi/location/LocationInfo.java
Index: LocationInfo.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Contributors: Mathias Rupprecht <mm...@fja.com>
package org.apache.log4j.spi.location;
import org.apache.log4j.helpers.LogLog;
/**
The internal representation of caller location information.
@since 0.8.3
*/
public class LocationInfo implements java.io.Serializable {
/**
When location information is not available the constant
<code>NA</code> is returned. Current value of this string
constant is <b>?</b>. */
public static final String NA = "?";
static final long serialVersionUID = -1325822038990805636L;
/**
* NA_LOCATION_INFO is used in conjunction with deserialized LoggingEvents
* without real location info available.
* @since 1.3
*/
public static LocationInfo NA_LOCATION_INFO = new LocationInfo(NA, NA, NA, NA);
/**
Caller's line number.
*/
String lineNumber;
/**
Caller's file name.
*/
String fileName;
/**
Caller's fully qualified class name.
*/
String className;
/**
Caller's method name.
*/
String methodName;
/**
All available caller information, in the format
<code>fully.qualified.classname.of.caller.methodName(Filename.java:line)</code>
*/
transient String fullInfo;
public LocationInfo(
String fileName, String className, String methodName, String lineNumber) {
this.fileName = fileName;
this.className = className;
this.methodName = methodName;
this.lineNumber = lineNumber;
}
/**
Instantiate location information based on a Throwable. We
expect the Throwable <code>t</code>, to be in the format
<pre>
java.lang.Throwable
...
at org.apache.log4j.PatternLayout.format(PatternLayout.java:413)
at org.apache.log4j.FileAppender.doAppend(FileAppender.java:183)
at org.apache.log4j.Category.callAppenders(Category.java:131)
at org.apache.log4j.Category.log(Category.java:512)
at callers.fully.qualified.className.methodName(FileName.java:74)
...
</pre>
<p>However, we can also deal with JIT compilers that "lose" the
location information, especially between the parentheses.
*/
public LocationInfo(Throwable t, String fqnOfCallingClass) {
if (t == null) {
return;
}
LegacyExtractor.extract(this, t, fqnOfCallingClass);
}
public boolean equals(Object o) {
LogLog.info("equals called");
if (this == o) {
return true;
}
if (!(o instanceof LocationInfo)) {
LogLog.info("inequality point 1");
return false;
}
LocationInfo r = (LocationInfo) 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(!getLineNumber().equals(r.getLineNumber())){
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 String getLineNumber() {
return lineNumber;
}
/**
Returns the method name of the caller.
*/
public String getMethodName() {
return methodName;
}
/**
* fullInfo format is:
* <code>fully.qualified.classname.of.caller.methodName(Filename.java:line)</code>
*/
public String getFullInfo() {
if(fullInfo == null) {
fullInfo = getClassName()+"."+getMethodName()+"("+getFileName()+":"+
getLineNumber()+")";
}
return fullInfo;
}
public String toString() {
return "(class="+getClassName()+", file="+getFileName()+", line="+getLineNumber()+", methodName="+getMethodName();
}
}
1.1 logging-log4j/src/java/org/apache/log4j/spi/location/LegacyExtractor.java
Index: LegacyExtractor.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.spi.location;
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.LogLog;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Extract location information from a throwable. The techniques used here
* work on all JDK platforms including those prior to JDK 1.4.
*
* @since 1.3
* @author Ceki Gülcü
*/
public class LegacyExtractor {
// Check if we are running in IBM's visual age.
static boolean inVisualAge = false;
static {
try {
Class dummy = Class.forName("com.ibm.uvm.tools.DebugSupport");
inVisualAge = true;
LogLog.debug("Detected IBM VisualAge environment.");
} catch (Throwable e) {
; // nothing to do
}
}
private static StringWriter sw = new StringWriter();
private static PrintWriter pw = new PrintWriter(sw);
private LegacyExtractor() {
}
static void extract(LocationInfo li, Throwable t, String fqnOfCallingClass) {
String s;
// Protect against multiple access to sw.
synchronized (sw) {
t.printStackTrace(pw);
s = sw.toString();
sw.getBuffer().setLength(0);
}
//System.out.println("s is ["+s+"].");
int ibegin;
//System.out.println("s is ["+s+"].");
int iend;
// Given the current structure of the package, the line
// containing "org.apache.log4j.Category." should be printed just
// before the caller.
// This method of searching may not be fastest but it's safer
// than counting the stack depth which is not guaranteed to be
// constant across JVM implementations.
ibegin = s.lastIndexOf(fqnOfCallingClass);
if (ibegin == -1) {
return;
}
ibegin = s.indexOf(Layout.LINE_SEP, ibegin);
if (ibegin == -1) {
return;
}
ibegin += Layout.LINE_SEP_LEN;
// determine end of line
iend = s.indexOf(Layout.LINE_SEP, ibegin);
if (iend == -1) {
return;
}
// VA has a different stack trace format which doesn't
// need to skip the inital 'at'
if (!inVisualAge) {
// back up to first blank character
ibegin = s.lastIndexOf("at ", iend);
if (ibegin == -1) {
return;
}
// Add 3 to skip "at ";
ibegin += 3;
}
// everything between is the requested stack item
li.fullInfo = s.substring(ibegin, iend);
setFileName(li, li.fullInfo );
setClassName(li, li.fullInfo );
setMethodName(li, li.fullInfo );
setLineNumber(li, li.fullInfo );
}
/**
* Make a best-effort attemt at setting the fike name of the caller.
* This information may not always be available.
*/
static void setFileName(LocationInfo li, String fullInfo) {
if (fullInfo == null) {
li.fileName = LocationInfo.NA;
} else {
int iend = fullInfo.lastIndexOf(':');
if (iend == -1) {
li.fileName = LocationInfo.NA;
} else {
int ibegin = fullInfo.lastIndexOf('(', iend - 1);
li.fileName = fullInfo.substring(ibegin + 1, iend);
}
}
}
/**
* Make a best-effort attemt at setting the class name of the caller.
* This information may not always be available.
*/
static void setClassName(LocationInfo li, String fullInfo) {
if (fullInfo == null) {
li.className = LocationInfo.NA;
return;
}
// Starting the search from '(' is safer because there is
// potentially a dot between the parentheses.
int iend = fullInfo.lastIndexOf('(');
if (iend == -1) {
li.className = LocationInfo.NA;
} else {
iend = fullInfo.lastIndexOf('.', iend);
// This is because a stack trace in VisualAge looks like:
//java.lang.RuntimeException
// java.lang.Throwable()
// java.lang.Exception()
// java.lang.RuntimeException()
// void test.test.B.print()
// void test.test.A.printIndirect()
// void test.test.Run.main(java.lang.String [])
int ibegin = 0;
if (inVisualAge) {
ibegin = fullInfo.lastIndexOf(' ', iend) + 1;
}
if (iend == -1) {
li.className = LocationInfo.NA;
} else {
li.className = fullInfo.substring(ibegin, iend);
}
}
}
/**
* Make a best-effort attemt at setting the line number of the caller.
* This information may not always be available.
*/
static void setLineNumber(LocationInfo li, String fullInfo) {
if (fullInfo == null) {
li.lineNumber = LocationInfo.NA;
} else {
int iend = fullInfo.lastIndexOf(')');
int ibegin = fullInfo.lastIndexOf(':', iend - 1);
if (ibegin == -1) {
li.lineNumber = LocationInfo.NA;
} else {
li.lineNumber = fullInfo.substring(ibegin + 1, iend);
}
}
}
/**
* Make a best-effort attemt at setting the method name of the caller.
* This information may not always be available.
*/
static void setMethodName(LocationInfo li, String fullInfo) {
if (fullInfo == null) {
li.methodName = LocationInfo.NA;
} else {
int iend = fullInfo.lastIndexOf('(');
int ibegin = fullInfo.lastIndexOf('.', iend);
if (ibegin == -1) {
li.methodName = LocationInfo.NA;
} else {
li.methodName = fullInfo.substring(ibegin + 1, iend);
}
}
}
}
1.4 +1 -1 logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java
Index: DBReceiverJob.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBReceiverJob.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DBReceiverJob.java 3 Jun 2004 22:48:17 -0000 1.3
+++ DBReceiverJob.java 7 Sep 2004 17:16:02 -0000 1.4
@@ -21,10 +21,10 @@
import org.apache.log4j.helpers.Constants;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.scheduler.Job;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import org.apache.log4j.spi.location.LocationInfo;
import java.sql.Connection;
import java.sql.ResultSet;
1.2 +1 -1 logging-log4j/src/java/org/apache/log4j/db/DBAppender2.java
Index: DBAppender2.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBAppender2.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DBAppender2.java 26 May 2004 15:36:18 -0000 1.1
+++ DBAppender2.java 7 Sep 2004 17:16:02 -0000 1.2
@@ -20,8 +20,8 @@
import org.apache.log4j.db.dialect.SQLDialect;
import org.apache.log4j.db.dialect.Util;
import org.apache.log4j.helpers.LogLog;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
import java.sql.Connection;
import java.sql.PreparedStatement;
1.15 +1 -1 logging-log4j/src/java/org/apache/log4j/db/DBAppender.java
Index: DBAppender.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/db/DBAppender.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DBAppender.java 3 Jun 2004 22:48:17 -0000 1.14
+++ DBAppender.java 7 Sep 2004 17:16:02 -0000 1.15
@@ -20,8 +20,8 @@
import org.apache.log4j.db.dialect.SQLDialect;
import org.apache.log4j.db.dialect.Util;
import org.apache.log4j.helpers.LogLog;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
import java.sql.Connection;
import java.sql.PreparedStatement;
1.36 +1 -1 logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java
Index: ChainsawCyclicBufferTableModel.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ChainsawCyclicBufferTableModel.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- ChainsawCyclicBufferTableModel.java 31 Jul 2004 07:23:57 -0000 1.35
+++ ChainsawCyclicBufferTableModel.java 7 Sep 2004 17:16:02 -0000 1.36
@@ -36,8 +36,8 @@
import org.apache.log4j.helpers.Constants;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.rule.Rule;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
1.3 +0 -2 logging-log4j/tests/src/java/org/apache/log4j/performance/Loop.java
Index: Loop.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/performance/Loop.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Loop.java 6 Sep 2004 15:39:54 -0000 1.2
+++ Loop.java 7 Sep 2004 17:16:02 -0000 1.3
@@ -16,9 +16,7 @@
package org.apache.log4j.performance;
-import org.apache.log4j.Appender;
import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
1.8 +1 -1 logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java
Index: FullCycleDBTest.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/db/FullCycleDBTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FullCycleDBTest.java 24 May 2004 16:14:34 -0000 1.7
+++ FullCycleDBTest.java 7 Sep 2004 17:16:02 -0000 1.8
@@ -32,10 +32,10 @@
import org.apache.log4j.helpers.IntializationUtil;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.joran.JoranConfigurator;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.RootLogger;
+import org.apache.log4j.spi.location.LocationInfo;
/**
1.35 +1 -1 logging-log4j/src/java/org/apache/log4j/HTMLLayout.java
Index: HTMLLayout.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/HTMLLayout.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- HTMLLayout.java 3 Jun 2004 21:57:09 -0000 1.34
+++ HTMLLayout.java 7 Sep 2004 17:16:02 -0000 1.35
@@ -20,8 +20,8 @@
import java.io.Writer;
import org.apache.log4j.helpers.Transform;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* This layout outputs events in a HTML table.
1.5 +2 -2 logging-log4j/src/java/org/apache/log4j/lf5/LF5Appender.java
Index: LF5Appender.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/lf5/LF5Appender.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LF5Appender.java 9 May 2004 18:37:56 -0000 1.4
+++ LF5Appender.java 7 Sep 2004 17:16:03 -0000 1.5
@@ -10,8 +10,8 @@
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
import java.awt.*;
@@ -100,7 +100,7 @@
record.setCategory(category);
record.setMessage(logMessage);
- record.setLocation(locationInfo.fullInfo);
+ record.setLocation(locationInfo.getFullInfo());
record.setMillis(time);
record.setThreadDescription(threadDescription);
1.1 logging-log4j/tests/src/java/org/apache/log4j/spi/location/LocationInfoTest.java
Index: LocationInfoTest.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.spi.location;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.location.LocationInfo;
import junit.framework.TestCase;
/**
*
* Very simple test verifying that LocationInfo extraction works, at least in
* simple cases.
*
* Note that this test is indetation sensitive. See lines commented as
* "LINE NUMBER:"
*
* @author Ceki
*/
public class LocationInfoTest extends TestCase {
Logger logger = Logger.getLogger(LocationInfoTest.class);
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
BasicConfigurator.configure();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
LogManager.shutdown();
}
/**
* Constructor for LocationInfoTest.
* @param arg0
*/
public LocationInfoTest(String arg0) {
super(arg0);
}
/*
* Class to test for boolean equals(Object)
*/
public void testEqualsObject() {
Throwable t1 = new Throwable();
Throwable t2 = new Throwable();
LoggingEvent le = new LoggingEvent("org.apache.log4j.spi.LoggingEvent", logger, Level.DEBUG,
"toto", null);
// LINE NUMBER: line extraction is done from on line 79 (following line)
LocationInfo li = le.getLocationInformation();
if(li == LocationInfo.NA_LOCATION_INFO) {
fail("For regular events, location info should not be LocationInfo.NA_LOCATION_INFO ");
}
assertEquals(this.getClass().getName(), li.getClassName());
assertEquals("LocationInfoTest.java", li.getFileName());
// LINE NUMBER: change the following number if lines are moved
assertEquals("79", li.getLineNumber());
assertEquals("testEqualsObject", li.getMethodName());
/*ThrowableInformation te1 = new ThrowableInformation(e1);
ThrowableInformation te2 = new ThrowableInformation(e2);
assertEquals(te1, te1);
assertEquals(te2, te2);
boolean eq1 = te1.equals(te2);
assertEquals(false, eq1);
boolean eq2 = te1.equals(null);
assertEquals(false, eq2);
*/
}
}
1.6 +1 -1 logging-log4j/src/java/org/apache/log4j/pattern/MethodLocationPatternConverter.java
Index: MethodLocationPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/MethodLocationPatternConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MethodLocationPatternConverter.java 28 May 2004 16:28:56 -0000 1.5
+++ MethodLocationPatternConverter.java 7 Sep 2004 17:16:04 -0000 1.6
@@ -16,8 +16,8 @@
package org.apache.log4j.pattern;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* Return the event's line location information in a StringBuffer.
1.6 +1 -1 logging-log4j/src/java/org/apache/log4j/pattern/FileLocationPatternConverter.java
Index: FileLocationPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/FileLocationPatternConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileLocationPatternConverter.java 28 May 2004 16:28:56 -0000 1.5
+++ FileLocationPatternConverter.java 7 Sep 2004 17:16:04 -0000 1.6
@@ -16,8 +16,8 @@
package org.apache.log4j.pattern;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* Return the event's line location information in a StringBuffer.
1.6 +1 -1 logging-log4j/src/java/org/apache/log4j/pattern/LineLocationPatternConverter.java
Index: LineLocationPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/LineLocationPatternConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LineLocationPatternConverter.java 28 May 2004 16:28:56 -0000 1.5
+++ LineLocationPatternConverter.java 7 Sep 2004 17:16:04 -0000 1.6
@@ -16,8 +16,8 @@
package org.apache.log4j.pattern;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* Return the event's line location information in a StringBuffer.
1.6 +2 -2 logging-log4j/src/java/org/apache/log4j/pattern/FullLocationPatternConverter.java
Index: FullLocationPatternConverter.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/pattern/FullLocationPatternConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FullLocationPatternConverter.java 28 May 2004 16:28:56 -0000 1.5
+++ FullLocationPatternConverter.java 7 Sep 2004 17:16:04 -0000 1.6
@@ -16,8 +16,8 @@
package org.apache.log4j.pattern;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* Return the event's line location information in a StringBuffer.
@@ -41,7 +41,7 @@
LocationInfo locationInfo = event.getLocationInformation();
if (locationInfo!=null) {
- buf.append(locationInfo.fullInfo);
+ buf.append(locationInfo.getFullInfo());
}
return buf;
1.63 +1 -1 logging-log4j/tests/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/logging-log4j/tests/build.xml,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- build.xml 5 Aug 2004 19:25:51 -0000 1.62
+++ build.xml 7 Sep 2004 17:16:04 -0000 1.63
@@ -528,7 +528,7 @@
<junit printsummary="yes" fork="yes" haltonfailure="yes">
<classpath refid="tests.classpath"/>
<formatter type="plain" usefile="false"/>
- <test name="org.apache.log4j.spi.LocationInfoTest" />
+ <test name="org.apache.log4j.spi.location.LocationInfoTest" />
</junit>
</target>
1.5 +1 -1 logging-log4j/src/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java
Index: LayoutEditorPane.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/layout/LayoutEditorPane.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LayoutEditorPane.java 10 May 2004 09:48:54 -0000 1.4
+++ LayoutEditorPane.java 7 Sep 2004 17:16:04 -0000 1.5
@@ -19,9 +19,9 @@
import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.ChainsawConstants;
import org.apache.log4j.chainsaw.icons.ChainsawIcons;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import org.apache.log4j.spi.location.LocationInfo;
import java.awt.Dimension;
import java.awt.Frame;
1.10 +1 -1 logging-log4j/src/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java
Index: EventDetailLayout.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/layout/EventDetailLayout.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EventDetailLayout.java 9 Jul 2004 05:43:46 -0000 1.9
+++ EventDetailLayout.java 7 Sep 2004 17:16:05 -0000 1.10
@@ -19,8 +19,8 @@
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
import java.io.IOException;
import java.io.Writer;
1.15 +1 -1 logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java
Index: LogFilePatternReceiver.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/varia/LogFilePatternReceiver.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- LogFilePatternReceiver.java 26 Jul 2004 07:39:31 -0000 1.14
+++ LogFilePatternReceiver.java 7 Sep 2004 17:16:05 -0000 1.15
@@ -38,9 +38,9 @@
import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.rule.ExpressionRule;
import org.apache.log4j.rule.Rule;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ThrowableInformation;
+import org.apache.log4j.spi.location.LocationInfo;
/**
1.10 +1 -1 logging-log4j/src/java/org/apache/log4j/chainsaw/filter/FilterModel.java
Index: FilterModel.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/filter/FilterModel.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FilterModel.java 12 May 2004 06:37:30 -0000 1.9
+++ FilterModel.java 7 Sep 2004 17:16:05 -0000 1.10
@@ -16,8 +16,8 @@
package org.apache.log4j.chainsaw.filter;
-import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.location.LocationInfo;
/**
* This class is used as a Model for Filtering, and retains the unique entries that
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
Refactoring of location info extraction
Posted by Ceki Gülcü <ce...@qos.ch>.
I have refactored location info extraction code into two separate
classes. (It used to be in the LocationInfo class.) This should pave
the way for a better extraction method based on StackTraceElements
introduced in JDK 1.4. See
http://marc.theaimsgroup.com/?t=108473346700001&r=1&w=2 for more
details.
At 07:16 PM 9/7/2004, you wrote:
>ceki 2004/09/07 10:16:05
>
> Modified: src/java/org/apache/log4j/xml UtilLoggingXMLDecoder.java
> XMLDecoder.java XMLLayout.java
> src/java/org/apache/log4j/spi LoggingEventFieldResolver.java
> LoggingEvent.java
> src/java/org/apache/log4j/db DBReceiverJob.java
> DBAppender2.java DBAppender.java
> src/java/org/apache/log4j/chainsaw
> ChainsawCyclicBufferTableModel.java
> tests/src/java/org/apache/log4j/performance Loop.java
> tests/src/java/org/apache/log4j/db FullCycleDBTest.java
> src/java/org/apache/log4j HTMLLayout.java
> src/java/org/apache/log4j/lf5 LF5Appender.java
> src/java/org/apache/log4j/pattern
> MethodLocationPatternConverter.java
> FileLocationPatternConverter.java
> LineLocationPatternConverter.java
> FullLocationPatternConverter.java
> tests build.xml
> src/java/org/apache/log4j/chainsaw/layout
> LayoutEditorPane.java EventDetailLayout.java
> src/java/org/apache/log4j/varia LogFilePatternReceiver.java
> src/java/org/apache/log4j/chainsaw/filter FilterModel.java
> Added: src/java/org/apache/log4j/spi/location LocationInfo.java
> LegacyExtractor.java
> tests/src/java/org/apache/log4j/spi/location
> LocationInfoTest.java
> Removed: src/java/org/apache/log4j/spi LocationInfo.java
> Log:
> - Created a new o.a.l.spi.location package
>
> - Moved o.a.l.spi.LocationInfo class to o.a.l.spi.location.LocationInfo
>
> - Updated many classes to reflect the name change
>
> - The location info extraction code has beed factored out to its own
> class. New and improved extraction strategies to follow.
>
> - Previously "transient" fields in LocationInfo are now serialized.
>
> Revision Changes Path
> 1.18 +1
> -1 logging-log4j/src/java/org/apache/log4j/xml/UtilLoggingXMLDecoder.java
>
--
Ceki Gülcü
For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org