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 ca...@apache.org on 2007/04/24 18:12:53 UTC
svn commit: r531995 - in /logging/log4j/branches/v1_2-branch:
src/java/org/apache/log4j/spi/LocationInfo.java
tests/src/java/org/apache/log4j/CoreTestSuite.java
tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
Author: carnold
Date: Tue Apr 24 09:12:50 2007
New Revision: 531995
URL: http://svn.apache.org/viewvc?view=rev&rev=531995
Log:
Bug 42108: Fix LocationInfo(String fileName, ...) and add unit test
Added:
logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
Modified:
logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java
logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
Modified: logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java?view=diff&rev=531995&r1=531994&r2=531995
==============================================================================
--- logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java (original)
+++ logging/log4j/branches/v1_2-branch/src/java/org/apache/log4j/spi/LocationInfo.java Tue Apr 24 09:12:50 2007
@@ -154,6 +154,22 @@
this.fullInfo = s.substring(ibegin, iend);
}
+ /**
+ * Appends a location fragment to a buffer to build the
+ * full location info.
+ * @param buf StringBuffer to receive content.
+ * @param fragment fragment of location (class, method, file, line),
+ * if null the value of NA will be appended.
+ * @since 1.2.15
+ */
+ private static final void appendFragment(final StringBuffer buf,
+ final String fragment) {
+ if (fragment == null) {
+ buf.append(NA);
+ } else {
+ buf.append(fragment);
+ }
+ }
/**
* Create new instance.
@@ -161,6 +177,8 @@
* @param classname class name
* @param method method
* @param line source line number
+ *
+ * @since 1.2.15
*/
public LocationInfo(
final String file,
@@ -171,6 +189,16 @@
this.className = classname;
this.methodName = method;
this.lineNumber = line;
+ StringBuffer buf = new StringBuffer();
+ appendFragment(buf, classname);
+ buf.append(".");
+ appendFragment(buf, method);
+ buf.append("(");
+ appendFragment(buf, file);
+ buf.append(":");
+ appendFragment(buf, line);
+ buf.append(")");
+ this.fullInfo = buf.toString();
}
/**
Modified: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java?view=diff&rev=531995&r1=531994&r2=531995
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java (original)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/CoreTestSuite.java Tue Apr 24 09:12:50 2007
@@ -48,6 +48,7 @@
s.addTestSuite(org.apache.log4j.PatternLayoutTest.class);
s.addTestSuite(org.apache.log4j.spi.LoggingEventTest.class);
s.addTestSuite(org.apache.log4j.spi.ThrowableInformationTest.class);
+ s.addTestSuite(org.apache.log4j.spi.LocationInfoTest.class);
s.addTestSuite(org.apache.log4j.PropertyConfiguratorTest.class);
return s;
}
Added: logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java?view=auto&rev=531995
==============================================================================
--- logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java (added)
+++ logging/log4j/branches/v1_2-branch/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java Tue Apr 24 09:12:50 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for LocationInfo.
+ */
+public class LocationInfoTest extends TestCase {
+
+ /**
+ * Tests four parameter constructor.
+ */
+ public void testFourParamConstructor() {
+ final String className = LocationInfoTest.class.getName();
+ final String methodName = "testFourParamConstructor";
+ final String fileName = "LocationInfoTest.java";
+ final String lineNumber = "41";
+ LocationInfo li = new LocationInfo(fileName,
+ className, methodName, lineNumber);
+ assertEquals(className, li.getClassName());
+ assertEquals(methodName, li.getMethodName());
+ assertEquals(fileName, li.getFileName());
+ assertEquals(lineNumber, li.getLineNumber());
+ assertEquals(className + "." + methodName
+ + "(" + fileName + ":" + lineNumber + ")",
+ li.fullInfo);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org