[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-95-g821d05c
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Mar 18 21:33:08 CET 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 821d05c90831d9f07d00bbc3f004561c37c1a0c0 (commit)
from e13257d75b2b4439c4c98b85e25a76611080a3d4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=821d05c90831d9f07d00bbc3f004561c37c1a0c0
http://github.com/ceki/logback/commit/821d05c90831d9f07d00bbc3f004561c37c1a0c0
commit 821d05c90831d9f07d00bbc3f004561c37c1a0c0
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Mar 18 21:31:57 2010 +0100
- additional tests and minor changes
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
index 99a4a58..b9785c7 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
@@ -37,14 +37,14 @@ public class EnsureExceptionHandling implements
*
*/
public void process(Converter<ILoggingEvent> head) {
+ if(head == null) {
+ // this should never happen
+ throw new IllegalArgumentException("cannot process empty chain");
+ }
if (!chainHandlesThrowable(head)) {
Converter<ILoggingEvent> tail = ConverterUtil.findTail(head);
Converter<ILoggingEvent> exConverter = new ExtendedThrowableProxyConverter();
- if (tail == null) {
- head = exConverter;
- } else {
- tail.setNext(exConverter);
- }
+ tail.setNext(exConverter);
}
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
index 4c8cf51..24dc122 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
@@ -19,19 +19,17 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
-import java.util.Random;
import org.junit.Test;
import org.slf4j.MDC;
-import ch.qos.logback.classic.util.CopyOnInheritThreadLocal;
-import ch.qos.logback.classic.util.LogbackMDCAdapter;
+import ch.qos.logback.core.testUtil.RandomUtil;
public class LogbackMDCAdapterTest {
final static String A_SUFFIX = "A_SUFFIX";
- int diff = new Random().nextInt();
+ int diff = RandomUtil.getPositiveInt();
/**
* Test that CopyOnInheritThreadLocal does not barf when the
diff --git a/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java b/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
index c163434..2e3c698 100644
--- a/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
+++ b/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
@@ -15,8 +15,6 @@ package org.slf4j.impl;
import static org.junit.Assert.assertEquals;
-import java.util.Random;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -28,11 +26,12 @@ import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.StatusPrinter;
public class RecursiveInitializationTest {
- int diff = new Random().nextInt();
+ int diff = RandomUtil.getPositiveInt();
@Before
public void setUp() throws Exception {
diff --git a/logback-classic/src/test/java/org/slf4j/impl/RecursiveLBAppender.java b/logback-classic/src/test/java/org/slf4j/impl/RecursiveLBAppender.java
index c444d9c..7eeb7a7 100644
--- a/logback-classic/src/test/java/org/slf4j/impl/RecursiveLBAppender.java
+++ b/logback-classic/src/test/java/org/slf4j/impl/RecursiveLBAppender.java
@@ -15,7 +15,6 @@ package org.slf4j.impl;
import java.util.ArrayList;
import java.util.List;
-import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -23,6 +22,7 @@ import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.testUtil.RandomUtil;
public class RecursiveLBAppender extends AppenderBase<ILoggingEvent> {
@@ -41,7 +41,7 @@ public class RecursiveLBAppender extends AppenderBase<ILoggingEvent> {
@Override
public void start() {
- int diff = new Random().nextInt();
+ int diff = RandomUtil.getPositiveInt();
Logger logger = LoggerFactory.getLogger("ResursiveLBAppender"+diff);
logger.info("testing");
super.start();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java b/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
index 9946454..8b7661d 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/ConsoleAppender.java
@@ -13,6 +13,8 @@
*/
package ch.qos.logback.core;
+import java.util.Arrays;
+
import ch.qos.logback.core.joran.spi.ConsoleTarget;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.WarnStatus;
@@ -41,6 +43,7 @@ public class ConsoleAppender<E> extends OutputStreamAppender<E> {
public void setTarget(String value) {
ConsoleTarget t = ConsoleTarget.findByName(value.trim());
if (t == null) {
+ System.out.println("**************");
targetWarn(value);
} else {
target = t;
@@ -58,8 +61,10 @@ public class ConsoleAppender<E> extends OutputStreamAppender<E> {
}
private void targetWarn(String val) {
- Status status = new WarnStatus("[" + val + " should be in " + ConsoleTarget.values(), this);
- status.add(new WarnStatus("Using previously set target, System.out by default.", this));
+ Status status = new WarnStatus("[" + val + "] should be one of "
+ + Arrays.toString(ConsoleTarget.values()), this);
+ status.add(new WarnStatus(
+ "Using previously set target, System.out by default.", this));
addStatus(status);
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/ConverterUtil.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/ConverterUtil.java
index 19c8628..03f65e8 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/ConverterUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/ConverterUtil.java
@@ -36,15 +36,15 @@ public class ConverterUtil {
public static<E> Converter<E> findTail(Converter<E> head) {
- Converter<E> c = head;
- while (c != null) {
- Converter<E> next = c.getNext();
+ Converter<E> p = head;
+ while (p != null) {
+ Converter<E> next = p.getNext();
if (next == null) {
break;
} else {
- c = next;
+ p = next;
}
}
- return c;
+ return p;
}
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/FormatInfo.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/FormatInfo.java
index a424361..1f6c9a5 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/FormatInfo.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/FormatInfo.java
@@ -50,7 +50,7 @@ public class FormatInfo {
*/
public static FormatInfo valueOf(String str) throws IllegalArgumentException {
if (str == null) {
- new NullPointerException("Argument cannot be null");
+ throw new NullPointerException("Argument cannot be null");
}
FormatInfo fi = new FormatInfo();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java
index 0210484..6a76153 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java
@@ -71,7 +71,11 @@ abstract public class PatternLayoutBase<E> extends LayoutBase<E> {
}
public void start() {
- try {
+ if(pattern == null || pattern.length() == 0) {
+ addError("Empty or null pattern.");
+ return;
+ }
+ try {
Parser<E> p = new Parser<E>(pattern);
if (getContext() != null) {
p.setContext(getContext());
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
index 8e9abff..d5080d5 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
@@ -59,8 +59,8 @@ class TokenStream {
}
TokenStream(String pattern, IEscapeUtil escapeUtil) {
- if(pattern == null) {
- throw new NullPointerException("null pattern string not allowed");
+ if(pattern == null || pattern.length() == 0) {
+ throw new NullPointerException("null or empty pattern string not allowed");
}
this.pattern = pattern;
patternLength = pattern.length();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RegularEscapeUtil.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RegularEscapeUtil.java
index d4feaa0..b4a6295 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RegularEscapeUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/util/RegularEscapeUtil.java
@@ -43,7 +43,7 @@ public class RegularEscapeUtil implements IEscapeUtil {
break;
default:
String commaSeperatedEscapeChars = formatEscapeCharsForListing(escapeChars);
- new IllegalArgumentException("Illegal char '" + next + " at column "
+ throw new IllegalArgumentException("Illegal char '" + next + " at column "
+ pointer + ". Only \\\\, \\_" + commaSeperatedEscapeChars
+ ", \\t, \\n, \\r combinations are allowed as escape characters.");
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/AbstractAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/AbstractAppenderTest.java
index 61b0826..60457c8 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/AbstractAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/AbstractAppenderTest.java
@@ -23,6 +23,7 @@ import ch.qos.logback.core.Appender;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.status.StatusChecker;
+import ch.qos.logback.core.util.StatusPrinter;
@@ -31,7 +32,8 @@ abstract public class AbstractAppenderTest<E> {
abstract protected Appender<E> getAppender();
abstract protected Appender<E> getConfiguredAppender();
-
+ Context context = new ContextBase();
+
@Test
public void testNewAppender() {
// new appenders should be inactive
@@ -53,13 +55,11 @@ abstract public class AbstractAppenderTest<E> {
@Test
public void testNoStart() {
Appender<E> appender = getAppender();
- Context context = new ContextBase();
- appender.setContext(context);
appender.setName("doh");
// is null OK?
appender.doAppend(null);
StatusChecker checker = new StatusChecker(context.getStatusManager());
- //StatusPrinter.print(context.getStatusManager());
+ StatusPrinter.print(context);
assertTrue(checker.containsMatch("Attempted to append to non started appender \\[doh\\]."));
}
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java
index e8e015c..74bdd80 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/ConsoleAppenderTest.java
@@ -30,14 +30,15 @@ import ch.qos.logback.core.encoder.DummyEncoder;
import ch.qos.logback.core.encoder.EchoEncoder;
import ch.qos.logback.core.encoder.NopEncoder;
import ch.qos.logback.core.layout.DummyLayout;
-
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusChecker;
+import ch.qos.logback.core.util.StatusPrinter;
public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
XTeeOutputStream tee;
PrintStream original;
-
@Before
public void setUp() throws Exception {
original = System.out;
@@ -45,10 +46,10 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
// collect them so that the output can be compared against
// some expected output data
// tee = new TeeOutputStream(original);
-
+
// keep the console quiet
tee = new XTeeOutputStream(null);
-
+
// redirect System.out to tee
System.setOut(new PrintStream(tee));
}
@@ -60,8 +61,10 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
@Override
public Appender<Object> getAppender() {
- return new ConsoleAppender<Object>();
- }
+ ConsoleAppender<Object> ca = new ConsoleAppender<Object>();
+ ca.setContext(context);
+ return ca;
+ }
protected Appender<Object> getConfiguredAppender() {
ConsoleAppender<Object> ca = new ConsoleAppender<Object>();
@@ -78,7 +81,7 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
ca.doAppend(new Object());
assertEquals(DummyLayout.DUMMY, tee.toString());
}
-
+
@org.junit.Test
public void testOpen() {
ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
@@ -88,9 +91,10 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
ca.start();
ca.doAppend(new Object());
ca.stop();
- assertEquals("open"+CoreConstants.LINE_SEPARATOR+DummyLayout.DUMMY, tee.toString());
+ assertEquals("open" + CoreConstants.LINE_SEPARATOR + DummyLayout.DUMMY, tee
+ .toString());
}
-
+
@Test
public void testClose() {
ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
@@ -114,16 +118,15 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
ca.setEncoder(encoder);
ca.start();
ca.doAppend("a");
- assertEquals("a"+CoreConstants.LINE_SEPARATOR, tee.toString());
-
+ assertEquals("a" + CoreConstants.LINE_SEPARATOR, tee.toString());
+
XTeeOutputStream newTee = new XTeeOutputStream(null);
System.setOut(new PrintStream(newTee));
ca.doAppend("b");
- assertEquals("b"+CoreConstants.LINE_SEPARATOR, newTee.toString());
+ assertEquals("b" + CoreConstants.LINE_SEPARATOR, newTee.toString());
}
-
- @Test
+ @Test
public void testUTF16BE() throws UnsupportedEncodingException {
ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
DummyEncoder<Object> dummyEncoder = new DummyEncoder<Object>();
@@ -135,5 +138,21 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
assertEquals(DummyLayout.DUMMY, new String(tee.toByteArray(), encodingName));
}
+ @Test
+ public void wrongTarget() {
+ ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
+ EchoEncoder<Object> encoder = new EchoEncoder<Object>();
+ System.out.println("xxx");
+ ca.setTarget("foo");
+ ca.setEncoder(encoder);
+ ca.start();
+ ca.doAppend("a");
+ StatusChecker checker = new StatusChecker(context);
+ //21:28:01,246 + WARN in ch.qos.logback.core.ConsoleAppender[null] - [foo] should be one of [SystemOut, SystemErr]
+ //21:28:01,246 |-WARN in ch.qos.logback.core.ConsoleAppender[null] - Using previously set target, System.out by default.
+
+ checker.containsMatch(Status.ERROR, "\\[foo\\] should be one of \\[SystemOut, SystemErr\\]");
+
+ }
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/AbstractPatternLayoutBaseTest.java b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/AbstractPatternLayoutBaseTest.java
index 8236b9c..a659adb 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/AbstractPatternLayoutBaseTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/AbstractPatternLayoutBaseTest.java
@@ -79,12 +79,28 @@ abstract public class AbstractPatternLayoutBaseTest<E> {
PatternLayoutBase<E> plb = getPatternLayoutBase();
Context context = new ContextBase();
plb.setContext(context);
+ plb.setPattern(null);
plb.start();
String s = plb.doLayout(getEventObject());
assertEquals("", s);
StatusChecker checker = new StatusChecker(context.getStatusManager());
- //StatusPrinter.print(context.getStatusManager());
- assertTrue(checker.containsMatch("Failed to parse pattern \"null\""));
+ StatusPrinter.print(context);
+ assertTrue(checker.containsMatch("Empty or null pattern."));
+ }
+
+ @Test
+ public void testEmptyPattern() {
+ //System.out.println("testNullPattern");
+ PatternLayoutBase<E> plb = getPatternLayoutBase();
+ Context context = new ContextBase();
+ plb.setContext(context);
+ plb.setPattern("");
+ plb.start();
+ String s = plb.doLayout(getEventObject());
+ assertEquals("", s);
+ StatusChecker checker = new StatusChecker(context.getStatusManager());
+ StatusPrinter.print(context);
+ assertTrue(checker.containsMatch("Empty or null pattern."));
}
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/ParserTest.java b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/ParserTest.java
index e9d01e9..26ea464 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/ParserTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/ParserTest.java
@@ -14,6 +14,7 @@
package ch.qos.logback.core.pattern.parser;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
@@ -242,4 +243,15 @@ public class ParserTest {
assertEquals(witness, t);
}
}
+
+ @Test
+ public void empty() {
+ try {
+ Parser p = new Parser("");
+ p.parse();
+ fail("");
+ } catch(ScanException e) {
+
+ }
+ }
}
\ No newline at end of file
-----------------------------------------------------------------------
Summary of changes:
.../classic/pattern/EnsureExceptionHandling.java | 10 ++--
.../classic/util/LogbackMDCAdapterTest.java | 6 +--
.../slf4j/impl/RecursiveInitializationTest.java | 5 +-
.../java/org/slf4j/impl/RecursiveLBAppender.java | 4 +-
.../java/ch/qos/logback/core/ConsoleAppender.java | 9 +++-
.../ch/qos/logback/core/pattern/ConverterUtil.java | 10 ++--
.../ch/qos/logback/core/pattern/FormatInfo.java | 2 +-
.../logback/core/pattern/PatternLayoutBase.java | 6 ++-
.../logback/core/pattern/parser/TokenStream.java | 4 +-
.../core/pattern/util/RegularEscapeUtil.java | 2 +-
.../core/appender/AbstractAppenderTest.java | 8 ++--
.../logback/core/appender/ConsoleAppenderTest.java | 47 ++++++++++++++------
.../parser/AbstractPatternLayoutBaseTest.java | 20 ++++++++-
.../logback/core/pattern/parser/ParserTest.java | 12 +++++
14 files changed, 99 insertions(+), 46 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list