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 2010/03/01 06:24:56 UTC
svn commit: r917391 - in /logging/log4j/companions/extras/trunk: pom.xml
src/main/java/org/apache/log4j/LogMF.java
src/main/java/org/apache/log4j/LogSF.java
src/main/java/org/apache/log4j/LogXF.java
src/test/java/org/apache/log4j/TestLogXF.java
Author: carnold
Date: Mon Mar 1 05:24:55 2010
New Revision: 917391
URL: http://svn.apache.org/viewvc?rev=917391&view=rev
Log:
Bug 43277: Add LogMF.entering, exiting and .throwing methods
Added:
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogXF.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/TestLogXF.java
Modified:
logging/log4j/companions/extras/trunk/pom.xml
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogMF.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogSF.java
Modified: logging/log4j/companions/extras/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/pom.xml?rev=917391&r1=917390&r2=917391&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/pom.xml (original)
+++ logging/log4j/companions/extras/trunk/pom.xml Mon Mar 1 05:24:55 2010
@@ -77,6 +77,13 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<workingDirectory>target</workingDirectory>
@@ -87,6 +94,7 @@
<configuration>
<source>1.4</source>
<target>1.4</target>
+ <encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogMF.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogMF.java?rev=917391&r1=917390&r2=917391&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogMF.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogMF.java Mon Mar 1 05:24:55 2010
@@ -30,11 +30,7 @@
* format log messages using java.text.MessageFormat.
*
*/
-public final class LogMF {
- /**
- * Trace level.
- */
- private static final Level TRACE = new Level(5000, "TRACE", 7);
+public final class LogMF extends LogXF {
/**
* private constructor.
*
@@ -44,147 +40,6 @@
/**
- * Returns a Boolean instance representing the specified boolean.
- * Boolean.valueOf was added in JDK 1.4.
- * @param b a boolean value.
- * @return a Boolean instance representing b.
- */
- private static Boolean valueOf(final boolean b) {
- if (b) {
- return Boolean.TRUE;
- }
- return Boolean.FALSE;
- }
-
- /**
- * Returns a Character instance representing the specified char.
- * Character.valueOf was added in JDK 1.5.
- * @param c a character value.
- * @return a Character instance representing c.
- */
- private static Character valueOf(final char c) {
- return new Character(c);
- }
-
- /**
- * Returns a Byte instance representing the specified byte.
- * Byte.valueOf was added in JDK 1.5.
- * @param b a byte value.
- * @return a Byte instance representing b.
- */
- private static Byte valueOf(final byte b) {
- return new Byte(b);
- }
-
- /**
- * Returns a Short instance representing the specified short.
- * Short.valueOf was added in JDK 1.5.
- * @param b a short value.
- * @return a Byte instance representing b.
- */
- private static Short valueOf(final short b) {
- return new Short(b);
- }
-
- /**
- * Returns an Integer instance representing the specified int.
- * Integer.valueOf was added in JDK 1.5.
- * @param b an int value.
- * @return an Integer instance representing b.
- */
- private static Integer valueOf(final int b) {
- return new Integer(b);
- }
-
- /**
- * Returns a Long instance representing the specified long.
- * Long.valueOf was added in JDK 1.5.
- * @param b a long value.
- * @return a Long instance representing b.
- */
- private static Long valueOf(final long b) {
- return new Long(b);
- }
-
- /**
- * Returns a Float instance representing the specified float.
- * Float.valueOf was added in JDK 1.5.
- * @param b a float value.
- * @return a Float instance representing b.
- */
- private static Float valueOf(final float b) {
- return new Float(b);
- }
-
- /**
- * Returns a Double instance representing the specified double.
- * Double.valueOf was added in JDK 1.5.
- * @param b a double value.
- * @return a Byte instance representing b.
- */
- private static Double valueOf(final double b) {
- return new Double(b);
- }
-
-
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @return new array.
- */
- private static Object[] toArray(final Object param1) {
- return new Object[] {
- param1
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2) {
- return new Object[] {
- param1, param2
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @param param3 parameter 3.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2,
- final Object param3) {
- return new Object[] {
- param1, param2, param3
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @param param3 parameter 3.
- * @param param4 parameter 4.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2,
- final Object param3,
- final Object param4) {
- return new Object[] {
- param1, param2, param3, param4
- };
- }
-
- /**
* Formats arguments using a minimal subset
* of MessageFormat syntax.
* @param pattern pattern, may not be null.
@@ -1712,4 +1567,5 @@
toArray(param0, param1, param2, param3)));
}
}
+
}
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogSF.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogSF.java?rev=917391&r1=917390&r2=917391&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogSF.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogSF.java Mon Mar 1 05:24:55 2010
@@ -27,11 +27,7 @@
* style formatter.
*
*/
-public final class LogSF {
- /**
- * Trace level.
- */
- private static final Level TRACE = new Level(5000, "TRACE", 7);
+public final class LogSF extends LogXF {
/**
* private constructor.
*
@@ -41,147 +37,6 @@
- /**
- * Returns a Boolean instance representing the specified boolean.
- * Boolean.valueOf was added in JDK 1.4.
- * @param b a boolean value.
- * @return a Boolean instance representing b.
- */
- private static Boolean valueOf(final boolean b) {
- if (b) {
- return Boolean.TRUE;
- }
- return Boolean.FALSE;
- }
-
- /**
- * Returns a Character instance representing the specified char.
- * Character.valueOf was added in JDK 1.5.
- * @param c a character value.
- * @return a Character instance representing c.
- */
- private static Character valueOf(final char c) {
- return new Character(c);
- }
-
- /**
- * Returns a Byte instance representing the specified byte.
- * Byte.valueOf was added in JDK 1.5.
- * @param b a byte value.
- * @return a Byte instance representing b.
- */
- private static Byte valueOf(final byte b) {
- return new Byte(b);
- }
-
- /**
- * Returns a Short instance representing the specified short.
- * Short.valueOf was added in JDK 1.5.
- * @param b a short value.
- * @return a Byte instance representing b.
- */
- private static Short valueOf(final short b) {
- return new Short(b);
- }
-
- /**
- * Returns an Integer instance representing the specified int.
- * Integer.valueOf was added in JDK 1.5.
- * @param b an int value.
- * @return an Integer instance representing b.
- */
- private static Integer valueOf(final int b) {
- return new Integer(b);
- }
-
- /**
- * Returns a Long instance representing the specified long.
- * Long.valueOf was added in JDK 1.5.
- * @param b a long value.
- * @return a Long instance representing b.
- */
- private static Long valueOf(final long b) {
- return new Long(b);
- }
-
- /**
- * Returns a Float instance representing the specified float.
- * Float.valueOf was added in JDK 1.5.
- * @param b a float value.
- * @return a Float instance representing b.
- */
- private static Float valueOf(final float b) {
- return new Float(b);
- }
-
- /**
- * Returns a Double instance representing the specified double.
- * Double.valueOf was added in JDK 1.5.
- * @param b a double value.
- * @return a Byte instance representing b.
- */
- private static Double valueOf(final double b) {
- return new Double(b);
- }
-
-
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @return new array.
- */
- private static Object[] toArray(final Object param1) {
- return new Object[] {
- param1
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2) {
- return new Object[] {
- param1, param2
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @param param3 parameter 3.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2,
- final Object param3) {
- return new Object[] {
- param1, param2, param3
- };
- }
-
- /**
- * Create new array.
- * @param param1 parameter 1.
- * @param param2 parameter 2.
- * @param param3 parameter 3.
- * @param param4 parameter 4.
- * @return new array.
- */
- private static Object[] toArray(final Object param1,
- final Object param2,
- final Object param3,
- final Object param4) {
- return new Object[] {
- param1, param2, param3, param4
- };
- }
-
/**
* Formats arguments using SLF4J-like formatter.
Added: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogXF.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogXF.java?rev=917391&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogXF.java (added)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/LogXF.java Mon Mar 1 05:24:55 2010
@@ -0,0 +1,372 @@
+/*
+ * 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;
+
+import org.apache.log4j.spi.LoggingEvent;
+
+public class LogXF {
+ /**
+ * Trace level.
+ */
+ protected static final Level TRACE = new Level(5000, "TRACE", 7);
+ /**
+ * Fully Qualified Class Name of this class.
+ */
+ private static final String FQCN = LogXF.class.getName();
+
+ protected LogXF() {
+ }
+
+ /**
+ * Returns a Boolean instance representing the specified boolean.
+ * Boolean.valueOf was added in JDK 1.4.
+ *
+ * @param b a boolean value.
+ * @return a Boolean instance representing b.
+ */
+ protected static Boolean valueOf(final boolean b) {
+ if (b) {
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+
+ /**
+ * Returns a Character instance representing the specified char.
+ * Character.valueOf was added in JDK 1.5.
+ *
+ * @param c a character value.
+ * @return a Character instance representing c.
+ */
+ protected static Character valueOf(final char c) {
+ return new Character(c);
+ }
+
+ /**
+ * Returns a Byte instance representing the specified byte.
+ * Byte.valueOf was added in JDK 1.5.
+ *
+ * @param b a byte value.
+ * @return a Byte instance representing b.
+ */
+ protected static Byte valueOf(final byte b) {
+ return new Byte(b);
+ }
+
+ /**
+ * Returns a Short instance representing the specified short.
+ * Short.valueOf was added in JDK 1.5.
+ *
+ * @param b a short value.
+ * @return a Byte instance representing b.
+ */
+ protected static Short valueOf(final short b) {
+ return new Short(b);
+ }
+
+ /**
+ * Returns an Integer instance representing the specified int.
+ * Integer.valueOf was added in JDK 1.5.
+ *
+ * @param b an int value.
+ * @return an Integer instance representing b.
+ */
+ protected static Integer valueOf(final int b) {
+ return new Integer(b);
+ }
+
+ /**
+ * Returns a Long instance representing the specified long.
+ * Long.valueOf was added in JDK 1.5.
+ *
+ * @param b a long value.
+ * @return a Long instance representing b.
+ */
+ protected static Long valueOf(final long b) {
+ return new Long(b);
+ }
+
+ /**
+ * Returns a Float instance representing the specified float.
+ * Float.valueOf was added in JDK 1.5.
+ *
+ * @param b a float value.
+ * @return a Float instance representing b.
+ */
+ protected static Float valueOf(final float b) {
+ return new Float(b);
+ }
+
+ /**
+ * Returns a Double instance representing the specified double.
+ * Double.valueOf was added in JDK 1.5.
+ *
+ * @param b a double value.
+ * @return a Byte instance representing b.
+ */
+ protected static Double valueOf(final double b) {
+ return new Double(b);
+ }
+
+ /**
+ * Create new array.
+ *
+ * @param param1 parameter 1.
+ * @return new array.
+ */
+ protected static Object[] toArray(final Object param1) {
+ return new Object[]{
+ param1
+ };
+ }
+
+ /**
+ * Create new array.
+ *
+ * @param param1 parameter 1.
+ * @param param2 parameter 2.
+ * @return new array.
+ */
+ protected static Object[] toArray(final Object param1,
+ final Object param2) {
+ return new Object[]{
+ param1, param2
+ };
+ }
+
+ /**
+ * Create new array.
+ *
+ * @param param1 parameter 1.
+ * @param param2 parameter 2.
+ * @param param3 parameter 3.
+ * @return new array.
+ */
+ protected static Object[] toArray(final Object param1,
+ final Object param2,
+ final Object param3) {
+ return new Object[]{
+ param1, param2, param3
+ };
+ }
+
+ /**
+ * Create new array.
+ *
+ * @param param1 parameter 1.
+ * @param param2 parameter 2.
+ * @param param3 parameter 3.
+ * @param param4 parameter 4.
+ * @return new array.
+ */
+ protected static Object[] toArray(final Object param1,
+ final Object param2,
+ final Object param3,
+ final Object param4) {
+ return new Object[]{
+ param1, param2, param3, param4
+ };
+ }
+
+ /**
+ * Log an entering message at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @since 1.1
+ */
+ public static void entering(final Logger logger,
+ final String sourceClass,
+ final String sourceMethod) {
+ if (logger.isDebugEnabled()) {
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ sourceClass + "." + sourceMethod + " ENTRY", null));
+ }
+ }
+
+ /**
+ * Log an entering message with a parameter at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param param parameter, may be null.
+ * @since 1.1
+ */
+ public static void entering(final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final String param) {
+ if (logger.isDebugEnabled()) {
+ String msg = sourceClass + "." + sourceMethod + " ENTRY " + param;
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ msg, null));
+ }
+ }
+
+ /**
+ * Log an entering message with a parameter at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param param parameter, may be null.
+ * @since 1.1
+ */
+ public static void entering(final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final Object param) {
+ if (logger.isDebugEnabled()) {
+ String msg = sourceClass + "." + sourceMethod + " ENTRY ";
+ if (param == null) {
+ msg += "null";
+ } else {
+ try {
+ msg += param;
+ } catch(Throwable ex) {
+ msg += "?";
+ }
+ }
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ msg, null));
+ }
+ }
+
+ /**
+ * Log an entering message with an array of parameters at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param params parameters, may be null.
+ * @since 1.1
+ */
+ public static void entering(final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final Object[] params) {
+ if (logger.isDebugEnabled()) {
+ String msg = sourceClass + "." + sourceMethod + " ENTRY ";
+ if (params != null && params.length > 0) {
+ String delim = "{";
+ for (int i = 0; i < params.length; i++) {
+ try {
+ msg += delim + params[i];
+ } catch(Throwable ex) {
+ msg += delim + "?";
+ }
+ delim = ",";
+ }
+ msg += "}";
+ } else {
+ msg += "{}";
+ }
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ msg, null));
+ }
+ }
+
+ /**
+ * Log an exiting message at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @since 1.1
+ */
+ public static void exiting(final Logger logger,
+ final String sourceClass,
+ final String sourceMethod) {
+ if (logger.isDebugEnabled()) {
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ sourceClass + "." + sourceMethod + " RETURN", null));
+ }
+ }
+
+ /**
+ * Log an exiting message with result at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param result result, may be null.
+ * @since 1.1
+ */
+ public static void exiting(
+ final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final String result) {
+ if (logger.isDebugEnabled()) {
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ sourceClass + "." + sourceMethod + " RETURN " + result, null));
+ }
+ }
+
+ /**
+ * Log an exiting message with result at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param result result, may be null.
+ * @since 1.1
+ */
+ public static void exiting(
+ final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final Object result) {
+ if (logger.isDebugEnabled()) {
+ String msg = sourceClass + "." + sourceMethod + " RETURN ";
+ if (result == null) {
+ msg += "null";
+ } else {
+ try {
+ msg += result;
+ } catch(Throwable ex) {
+ msg += "?";
+ }
+ }
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ msg, null));
+ }
+ }
+
+ /**
+ * Logs a throwing message at DEBUG level.
+ *
+ * @param logger logger, may not be null.
+ * @param sourceClass source class, may be null.
+ * @param sourceMethod method, may be null.
+ * @param thrown, throwable may be null.
+ * @param thrown the throwable.
+ * @since 1.1
+ */
+ public static void throwing(
+ final Logger logger,
+ final String sourceClass,
+ final String sourceMethod,
+ final Throwable thrown) {
+ if (logger.isDebugEnabled()) {
+ logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
+ sourceClass + "." + sourceMethod + " THROW", thrown));
+ }
+ }
+}
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/TestLogXF.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/TestLogXF.java?rev=917391&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/TestLogXF.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/TestLogXF.java Mon Mar 1 05:24:55 2010
@@ -0,0 +1,215 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Unit test for LogXF.
+ */
+public class TestLogXF extends TestCase {
+ /**
+ * Logger.
+ */
+ private final Logger logger = Logger.getLogger(
+ "org.apache.log4j.formatter.TestLogXF");
+
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public TestLogXF(String testName) {
+ super(testName);
+ }
+
+
+ /**
+ * Post test clean up.
+ */
+ public void tearDown() {
+ LogManager.resetConfiguration();
+ }
+
+ private static class BadStringifier {
+ private BadStringifier() {}
+ public static BadStringifier INSTANCE = new BadStringifier();
+ public String toString() {
+ throw new NullPointerException();
+ }
+ }
+
+
+ /**
+ * Test LogXF.entering with null class and method.
+ */
+ public void testEnteringNullNull() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, null, null);
+ assertEquals("null.null ENTRY", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.entering with null class, method and parameter.
+ */
+ public void testEnteringNullNullNull() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, null, null, (String) null);
+ assertEquals("null.null ENTRY null", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.entering with null class, method and parameters.
+ */
+ public void testEnteringNullNullNullArray() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, null, null, (Object[]) null);
+ assertEquals("null.null ENTRY {}", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.entering with class and method.
+ */
+ public void testEntering() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, "SomeClass", "someMethod");
+ assertEquals("SomeClass.someMethod ENTRY", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.entering with class, method and parameter.
+ */
+ public void testEnteringWithParam() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, "SomeClass", "someMethod", "someParam");
+ assertEquals("SomeClass.someMethod ENTRY someParam", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.entering with class, method and bad parameter.
+ */
+ public void testEnteringWithBadParam() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, "SomeClass", "someMethod", BadStringifier.INSTANCE);
+ assertEquals("SomeClass.someMethod ENTRY ?", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.entering with class, method and bad parameters.
+ */
+ public void testEnteringWithBadParams() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.entering(logger, "SomeClass", "someMethod", new Object[]{"param1",BadStringifier.INSTANCE});
+ assertEquals("SomeClass.someMethod ENTRY {param1,?}", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.exiting with null class and method.
+ */
+ public void testExitingNullNull() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.exiting(logger, null, null);
+ assertEquals("null.null RETURN", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.exiting with null class, method and parameter.
+ */
+ public void testExitingNullNullNull() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.exiting(logger, null, null, (String) null);
+ assertEquals("null.null RETURN null", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.exiting with class and method.
+ */
+ public void testExiting() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.exiting(logger, "SomeClass", "someMethod");
+ assertEquals("SomeClass.someMethod RETURN", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.exiting with class, method and return value.
+ */
+ public void testExitingWithValue() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.exiting(logger, "SomeClass", "someMethod", "someValue");
+ assertEquals("SomeClass.someMethod RETURN someValue", capture.getMessage());
+ }
+
+ /**
+ * Test LogXF.exiting with class, method and bad return value.
+ */
+ public void testExitingWithBadValue() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.exiting(logger, "SomeClass", "someMethod", BadStringifier.INSTANCE);
+ assertEquals("SomeClass.someMethod RETURN ?", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.throwing with null class, method and throwable.
+ */
+ public void testThrowingNullNullNull() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.throwing(logger, null, null, null);
+ assertEquals("null.null THROW", capture.getMessage());
+ }
+
+
+ /**
+ * Test LogXF.exiting with class and method.
+ */
+ public void testThrowing() {
+ LogCapture capture = new LogCapture(Level.DEBUG);
+ logger.setLevel(Level.DEBUG);
+ LogXF.throwing(logger, "SomeClass", "someMethod", new IllegalArgumentException());
+ assertEquals("SomeClass.someMethod THROW", capture.getMessage());
+ }
+
+ public void testJul() {
+ java.util.logging.Logger l = java.util.logging.Logger.getAnonymousLogger();
+ java.util.logging.Handler h = new java.util.logging.ConsoleHandler();
+ h.setLevel(java.util.logging.Level.FINER);
+ l.addHandler(h);
+ l.setLevel(java.util.logging.Level.FINER);
+ l.entering("SomeClass", "someMethod", "foo");
+ l.setLevel(java.util.logging.Level.FINER);
+ l.entering("SomeClass", "someMethod", BadStringifier.INSTANCE);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org