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/27 05:51:09 UTC
svn commit: r532947 [3/3] - in /logging/sandbox/log4j/formatter: ./
src/main/java/org/apache/log4j/ src/main/resources/META-INF/
src/test/java/org/apache/log4j/ src/test/resources/org/
src/test/resources/org/apache/ src/test/resources/org/apache/log4j/
Added: logging/sandbox/log4j/formatter/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/logging/sandbox/log4j/formatter/src/main/resources/META-INF/NOTICE?view=auto&rev=532947
==============================================================================
--- logging/sandbox/log4j/formatter/src/main/resources/META-INF/NOTICE (added)
+++ logging/sandbox/log4j/formatter/src/main/resources/META-INF/NOTICE Thu Apr 26 20:51:08 2007
@@ -0,0 +1,5 @@
+Apache LogMF Companion for log4j 1.2
+Copyright 2007 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
Modified: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogCapture.java
URL: http://svn.apache.org/viewvc/logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogCapture.java?view=diff&rev=532947&r1=532946&r2=532947
==============================================================================
--- logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogCapture.java (original)
+++ logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogCapture.java Thu Apr 26 20:51:08 2007
@@ -70,7 +70,6 @@
Assert.assertNotNull(event);
Assert.assertEquals(level, event.getLevel());
msg = event.getRenderedMessage();
- Assert.assertNotNull(msg);
break;
Copied: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/TestLogMF.java (from r532885, logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogMFTest.java)
URL: http://svn.apache.org/viewvc/logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/TestLogMF.java?view=diff&rev=532947&p1=logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogMFTest.java&r1=532885&p2=logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/TestLogMF.java&r2=532947
==============================================================================
--- logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/LogMFTest.java (original)
+++ logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/TestLogMF.java Thu Apr 26 20:51:08 2007
@@ -18,34 +18,49 @@
import junit.framework.TestCase;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-
+import java.io.CharArrayWriter;
import java.text.MessageFormat;
-
import java.util.Date;
/**
* Unit test for LogMF.
*/
-public class LogMFTest extends TestCase {
+public class TestLogMF extends TestCase {
+ /**
+ * Trace level.
+ */
+ private static final Level TRACE = getTraceLevel();
+
+ /**
+ * Gets Trace level.
+ * Trace level was not defined prior to log4j 1.2.12.
+ * @return trace level
+ */
+ private static Level getTraceLevel() {
+ try {
+ return (Level) Level.class.getField("TRACE").get(null);
+ } catch(Exception ex) {
+ return new Level(5000, "TRACE", 7);
+ }
+ }
+
/**
* Logger.
*/
private final Logger logger = Logger.getLogger(
- "org.apache.log4j.formatter.LogMFTest");
+ "org.apache.log4j.formatter.TestLogMF");
/**
* Create the test case
*
* @param testName name of the test case
*/
- public LogMFTest(String testName) {
+ public TestLogMF(String testName) {
super(testName);
}
+
/**
* Post test clean up.
*/
@@ -54,12 +69,236 @@
}
/**
+ * Test class name when logging through LogMF.
+ */
+ public void testClassName() {
+ CharArrayWriter writer = new CharArrayWriter();
+ PatternLayout layout = new PatternLayout("%C");
+ WriterAppender appender = new WriterAppender(layout, writer);
+ appender.activateOptions();
+ Logger.getRootLogger().addAppender(appender);
+ LogMF.debug(logger, null, Math.PI);
+ assertEquals(TestLogMF.class.getName(), writer.toString());
+ }
+
+ /**
+ * Test LogMF.trace with null pattern.
+ */
+ public void testTraceNullPattern() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, null, Math.PI);
+ assertNull(capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with no-field pattern.
+ */
+ public void testTraceNoArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "Hello, World", Math.PI);
+ assertEquals("Hello, World", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with malformed pattern.
+ */
+ public void testTraceBadPattern() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "Hello, {.", Math.PI);
+ assertEquals("Hello, {.", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with missing argument.
+ */
+ public void testTraceMissingArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "Hello, {0}World", new Object[0]);
+ assertEquals("Hello, {0}World", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with string argument.
+ */
+ public void testTraceString() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "Hello, {0}", "World");
+ assertEquals("Hello, World", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with null argument.
+ */
+ public void testTraceNull() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "Hello, {0}", (Object) null);
+ assertEquals("Hello, null", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with int argument.
+ */
+ public void testTraceInt() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ int val = 42;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 42", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with byte argument.
+ */
+ public void testTraceByte() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ byte val = 42;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 42", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with short argument.
+ */
+ public void testTraceShort() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ short val = 42;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 42", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with long argument.
+ */
+ public void testTraceLong() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ long val = 42;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 42", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with char argument.
+ */
+ public void testTraceChar() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ char val = 'C';
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration C", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with boolean argument.
+ */
+ public void testTraceBoolean() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ boolean val = true;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration true", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with float argument.
+ */
+ public void testTraceFloat() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ float val = 3.14f;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 3.14", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with single field pattern with double argument.
+ */
+ public void testTraceDouble() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ double val = 3.14;
+ LogMF.trace(logger, "Iteration {0}", val);
+ assertEquals("Iteration 3.14", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with two arguments.
+ */
+ public void testTraceTwoArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "{1}, {0}.", "World", "Hello");
+ assertEquals("Hello, World.", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with three arguments.
+ */
+ public void testTraceThreeArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "{1}{2} {0}.", "World", "Hello", ",");
+ assertEquals("Hello, World.", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with four arguments.
+ */
+ public void testTraceFourArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+ LogMF.trace(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
+ assertEquals("Hello, World.", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with Object[] argument.
+ */
+ public void testTraceArrayArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ Object[] args = new Object[] { "World", "Hello", ",", "." };
+ LogMF.trace(logger, "{1}{2} {0}{3}", args);
+ assertEquals("Hello, World.", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.trace with null Object[] argument.
+ */
+ public void testTraceNullArrayArg() {
+ LogCapture capture = new LogCapture(TRACE);
+ logger.setLevel(TRACE);
+
+ Object[] args = null;
+ LogMF.trace(logger, "{1}{2} {0}{3}", args);
+ assertEquals("{1}{2} {0}{3}", capture.getMessage());
+ }
+
+
+ /**
* Test LogMF.debug with null pattern.
*/
public void testDebugNullPattern() {
LogCapture capture = new LogCapture(Level.DEBUG);
LogMF.debug(logger, null, Math.PI);
- assertNull(capture.getMessage());
+ assertEquals(null, capture.getMessage());
}
/**
@@ -626,125 +865,125 @@
}
/**
- * Test LogMF.error with null pattern.
+ * Test LogMF.log with null pattern.
*/
- public void testErrorNullPattern() {
+ public void testLogNullPattern() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, null, Math.PI);
+ LogMF.log(logger, Level.ERROR, null, Math.PI);
assertNull(capture.getMessage());
}
/**
- * Test LogMF.error with no-field pattern.
+ * Test LogMF.log with no-field pattern.
*/
- public void testErrorNoArg() {
+ public void testLogNoArg() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Hello, World", Math.PI);
+ LogMF.log(logger, Level.ERROR, "Hello, World", Math.PI);
assertEquals("Hello, World", capture.getMessage());
}
/**
- * Test LogMF.error with malformed pattern.
+ * Test LogMF.log with malformed pattern.
*/
- public void testErrorBadPattern() {
+ public void testLogBadPattern() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Hello, {.", Math.PI);
+ LogMF.log(logger, Level.ERROR, "Hello, {.", Math.PI);
assertEquals("Hello, {.", capture.getMessage());
}
/**
- * Test LogMF.error with missing argument.
+ * Test LogMF.log with missing argument.
*/
- public void testErrorMissingArg() {
+ public void testLogMissingArg() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Hello, {0}World", new Object[0]);
+ LogMF.log(logger, Level.ERROR, "Hello, {0}World", new Object[0]);
assertEquals("Hello, {0}World", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with string argument.
+ * Test LogMF.log with single field pattern with string argument.
*/
- public void testErrorString() {
+ public void testLogString() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Hello, {0}", "World");
+ LogMF.log(logger, Level.ERROR, "Hello, {0}", "World");
assertEquals("Hello, World", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with null argument.
+ * Test LogMF.log with single field pattern with null argument.
*/
- public void testErrorNull() {
+ public void testLogNull() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Hello, {0}", (Object) null);
+ LogMF.log(logger, Level.ERROR, "Hello, {0}", (Object) null);
assertEquals("Hello, null", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with int argument.
+ * Test LogMF.log with single field pattern with int argument.
*/
- public void testErrorInt() {
+ public void testLogInt() {
LogCapture capture = new LogCapture(Level.ERROR);
int val = 42;
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with byte argument.
+ * Test LogMF.log with single field pattern with byte argument.
*/
- public void testErrorByte() {
+ public void testLogByte() {
LogCapture capture = new LogCapture(Level.ERROR);
byte val = 42;
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with short argument.
+ * Test LogMF.log with single field pattern with short argument.
*/
- public void testErrorShort() {
+ public void testLogShort() {
LogCapture capture = new LogCapture(Level.ERROR);
short val = 42;
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with long argument.
+ * Test LogMF.log with single field pattern with long argument.
*/
- public void testErrorLong() {
+ public void testLogLong() {
LogCapture capture = new LogCapture(Level.ERROR);
long val = 42;
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with char argument.
+ * Test LogMF.log with single field pattern with char argument.
*/
- public void testErrorChar() {
+ public void testLogChar() {
LogCapture capture = new LogCapture(Level.ERROR);
char val = 'C';
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration C", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with boolean argument.
+ * Test LogMF.log with single field pattern with boolean argument.
*/
- public void testErrorBoolean() {
+ public void testLogBoolean() {
LogCapture capture = new LogCapture(Level.ERROR);
boolean val = true;
- LogMF.error(logger, "Iteration {0}", val);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", val);
assertEquals("Iteration true", capture.getMessage());
}
/**
- * Test LogMF.error with single field pattern with float argument.
+ * Test LogMF.log with single field pattern with float argument.
*/
- public void testErrorFloat() {
+ public void testLogFloat() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Iteration {0}", (float) Math.PI);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", (float) Math.PI);
String expected = MessageFormat.format("Iteration {0}",
new Object[] { new Float(Math.PI) });
@@ -752,11 +991,11 @@
}
/**
- * Test LogMF.debug with single field pattern with double argument.
+ * Test LogMF.log with single field pattern with double argument.
*/
- public void testErrorDouble() {
+ public void testLogDouble() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "Iteration {0}", Math.PI);
+ LogMF.log(logger, Level.ERROR, "Iteration {0}", Math.PI);
String expected = MessageFormat.format("Iteration {0}",
new Object[] { new Double(Math.PI) });
@@ -764,162 +1003,177 @@
}
/**
- * Test LogMF.error with two arguments.
+ * Test LogMF.log with two arguments.
*/
- public void testErrorTwoArg() {
+ public void testLogTwoArg() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "{1}, {0}.", "World", "Hello");
+ LogMF.log(logger, Level.ERROR, "{1}, {0}.", "World", "Hello");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.error with three arguments.
+ * Test LogMF.log with three arguments.
*/
- public void testErrorThreeArg() {
+ public void testLogThreeArg() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "{1}{2} {0}.", "World", "Hello", ",");
+ LogMF.log(logger, Level.ERROR, "{1}{2} {0}.", "World", "Hello", ",");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.error with four arguments.
+ * Test LogMF.log with four arguments.
*/
- public void testErrorFourArg() {
+ public void testLogFourArg() {
LogCapture capture = new LogCapture(Level.ERROR);
- LogMF.error(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
+ LogMF.log(logger, Level.ERROR, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.error with Object[] argument.
+ * Test LogMF.log with Object[] argument.
*/
- public void testErrorArrayArg() {
+ public void testLogArrayArg() {
LogCapture capture = new LogCapture(Level.ERROR);
Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.error(logger, "{1}{2} {0}{3}", args);
+ LogMF.log(logger, Level.ERROR, "{1}{2} {0}{3}", args);
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.fatal with null pattern.
+ * Bundle name for resource bundle tests.
+ */
+ private static final String BUNDLE_NAME =
+ "org.apache.log4j.TestLogMFPatterns";
+
+ /**
+ * Test LogMF.logrb with null bundle name.
+ */
+ public void testLogrbNullBundle() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, null, "Iteration0", Math.PI);
+ assertEquals("Iteration0", capture.getMessage());
+ }
+
+ /**
+ * Test LogMF.logrb with null key.
*/
- public void testFatalNullPattern() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, null, Math.PI);
+ public void testLogrbNullKey() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, null, Math.PI);
assertNull(capture.getMessage());
}
/**
- * Test LogMF.fatal with no-field pattern.
+ * Test LogMF.logrb with no-field pattern.
*/
- public void testFatalNoArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Hello, World", Math.PI);
+ public void testLogrbNoArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello1", Math.PI);
assertEquals("Hello, World", capture.getMessage());
}
/**
- * Test LogMF.fatal with malformed pattern.
+ * Test LogMF.logrb with malformed pattern.
*/
- public void testFatalBadPattern() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Hello, {.", Math.PI);
+ public void testLogrbBadPattern() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Malformed", Math.PI);
assertEquals("Hello, {.", capture.getMessage());
}
/**
- * Test LogMF.fatal with missing argument.
+ * Test LogMF.logrb with missing argument.
*/
- public void testFatalMissingArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Hello, {0}World", new Object[0]);
+ public void testLogrbMissingArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello2", new Object[0]);
assertEquals("Hello, {0}World", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with string argument.
+ * Test LogMF.logrb with single field pattern with string argument.
*/
- public void testFatalString() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Hello, {0}", "World");
+ public void testLogrbString() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", "World");
assertEquals("Hello, World", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with null argument.
+ * Test LogMF.logrb with single field pattern with null argument.
*/
- public void testFatalNull() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Hello, {0}", (Object) null);
+ public void testLogrbNull() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Hello3", (Object) null);
assertEquals("Hello, null", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with int argument.
+ * Test LogMF.logrb with single field pattern with int argument.
*/
- public void testFatalInt() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbInt() {
+ LogCapture capture = new LogCapture(Level.ERROR);
int val = 42;
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with byte argument.
+ * Test LogMF.logrb with single field pattern with byte argument.
*/
- public void testFatalByte() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbByte() {
+ LogCapture capture = new LogCapture(Level.ERROR);
byte val = 42;
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with short argument.
+ * Test LogMF.logrb with single field pattern with short argument.
*/
- public void testFatalShort() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbShort() {
+ LogCapture capture = new LogCapture(Level.ERROR);
short val = 42;
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with long argument.
+ * Test LogMF.logrb with single field pattern with long argument.
*/
- public void testFatalLong() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbLong() {
+ LogCapture capture = new LogCapture(Level.ERROR);
long val = 42;
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration 42", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with char argument.
+ * Test LogMF.logrb with single field pattern with char argument.
*/
- public void testFatalChar() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbChar() {
+ LogCapture capture = new LogCapture(Level.ERROR);
char val = 'C';
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration C", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with boolean argument.
+ * Test LogMF.logrb with single field pattern with boolean argument.
*/
- public void testFatalBoolean() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbBoolean() {
+ LogCapture capture = new LogCapture(Level.ERROR);
boolean val = true;
- LogMF.fatal(logger, "Iteration {0}", val);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", val);
assertEquals("Iteration true", capture.getMessage());
}
/**
- * Test LogMF.fatal with single field pattern with float argument.
+ * Test LogMF.logrb with single field pattern with float argument.
*/
- public void testFatalFloat() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Iteration {0}", (float) Math.PI);
+ public void testLogrbFloat() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", (float) Math.PI);
String expected = MessageFormat.format("Iteration {0}",
new Object[] { new Float(Math.PI) });
@@ -927,11 +1181,11 @@
}
/**
- * Test LogMF.fatal with single field pattern with double argument.
+ * Test LogMF.logrb with single field pattern with double argument.
*/
- public void testFatalDouble() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "Iteration {0}", Math.PI);
+ public void testLogrbDouble() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR, BUNDLE_NAME, "Iteration0", Math.PI);
String expected = MessageFormat.format("Iteration {0}",
new Object[] { new Double(Math.PI) });
@@ -939,39 +1193,44 @@
}
/**
- * Test LogMF.fatal with two arguments.
+ * Test LogMF.logrb with two arguments.
*/
- public void testFatalTwoArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "{1}, {0}.", "World", "Hello");
+ public void testLogrbTwoArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR,
+ BUNDLE_NAME, "Hello4", "World", "Hello");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.fatal with three arguments.
+ * Test LogMF.logrb with three arguments.
*/
- public void testFatalThreeArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "{1}{2} {0}.", "World", "Hello", ",");
+ public void testLogrbThreeArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR,
+ BUNDLE_NAME, "Hello5", "World", "Hello", ",");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.fatal with four arguments.
+ * Test LogMF.logrb with four arguments.
*/
- public void testFatalFourArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
- LogMF.fatal(logger, "{1}{2} {0}{3}", "World", "Hello", ",", ".");
+ public void testLogrbFourArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
+ LogMF.logrb(logger, Level.ERROR,
+ BUNDLE_NAME, "Hello6", "World", "Hello", ",", ".");
assertEquals("Hello, World.", capture.getMessage());
}
/**
- * Test LogMF.fatal with Object[] argument.
+ * Test LogMF.logrb with Object[] argument.
*/
- public void testFatalArrayArg() {
- LogCapture capture = new LogCapture(Level.FATAL);
+ public void testLogrbArrayArg() {
+ LogCapture capture = new LogCapture(Level.ERROR);
Object[] args = new Object[] { "World", "Hello", ",", "." };
- LogMF.fatal(logger, "{1}{2} {0}{3}", args);
+ LogMF.logrb(logger, Level.ERROR,
+ BUNDLE_NAME, "Hello6", args);
assertEquals("Hello, World.", capture.getMessage());
}
+
}
Propchange: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/TestLogMF.java
------------------------------------------------------------------------------
svn:executable =
Added: logging/sandbox/log4j/formatter/src/test/resources/org/apache/log4j/TestLogMFPatterns.properties
URL: http://svn.apache.org/viewvc/logging/sandbox/log4j/formatter/src/test/resources/org/apache/log4j/TestLogMFPatterns.properties?view=auto&rev=532947
==============================================================================
--- logging/sandbox/log4j/formatter/src/test/resources/org/apache/log4j/TestLogMFPatterns.properties (added)
+++ logging/sandbox/log4j/formatter/src/test/resources/org/apache/log4j/TestLogMFPatterns.properties Thu Apr 26 20:51:08 2007
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+Iteration0=Iteration {0}
+Hello1=Hello, World
+Malformed=Hello, {.
+Hello2=Hello, {0}World
+Hello3=Hello, {0}
+Hello4={1}, {0}.
+Hello5={1}{2} {0}.
+Hello6={1}{2} {0}{3}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org