[logback-dev] svn commit: r998 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/status main/java/ch/qos/logback/core/util test/java/ch/qos/logback/core/util
noreply.seb at qos.ch
noreply.seb at qos.ch
Fri Nov 24 14:07:15 CET 2006
Author: seb
Date: Fri Nov 24 14:07:14 2006
New Revision: 998
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/StatusPrinterTest.java
Log:
Removed static system.out access from StatusBase
Better StatusPrinterTest
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/StatusBase.java Fri Nov 24 14:07:14 2006
@@ -15,9 +15,6 @@
abstract public class StatusBase implements Status {
- static {
- System.out.println("XXXXXXXXXXXX Loading StatusBase ");
- }
static private final List<Status> EMPTY_LIST = new ArrayList<Status>(0);
int level;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java Fri Nov 24 14:07:14 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.core.util;
+import java.io.PrintStream;
import java.util.Iterator;
import ch.qos.logback.core.Context;
@@ -17,7 +18,13 @@
import ch.qos.logback.core.status.StatusManager;
public class StatusPrinter {
+
+ private static PrintStream ps = System.out;
+ public static void setPrintStream(PrintStream printStream) {
+ ps = printStream;
+ }
+
public static void print(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context argument cannot be null");
@@ -25,7 +32,7 @@
StatusManager sm = context.getStatusManager();
if (sm == null) {
- System.out.println("WARN: Context named \"" + context.getName()
+ ps.println("WARN: Context named \"" + context.getName()
+ "\" has no status manager");
}
@@ -49,9 +56,9 @@
} else {
prefix = indentation + "|-";
}
- System.out.println(prefix+s);
+ ps.println(prefix+s);
if (s.getThrowable() != null) {
- s.getThrowable().printStackTrace(System.out);
+ s.getThrowable().printStackTrace(ps);
}
if(s.hasChildren()) {
Iterator<Status> ite = s.iterator();
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/StatusPrinterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/StatusPrinterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/StatusPrinterTest.java Fri Nov 24 14:07:14 2006
@@ -1,5 +1,8 @@
package ch.qos.logback.core.util;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
import junit.framework.TestCase;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
@@ -10,15 +13,24 @@
public class StatusPrinterTest extends TestCase {
+ ByteArrayOutputStream outputStream;
+ PrintStream ps;
+
public StatusPrinterTest(String arg0) {
super(arg0);
}
protected void setUp() throws Exception {
+ outputStream = new ByteArrayOutputStream();
+ ps = new PrintStream(outputStream);
+ StatusPrinter.setPrintStream(ps);
super.setUp();
}
protected void tearDown() throws Exception {
+ StatusPrinter.setPrintStream(System.out);
+ ps = null;
+ outputStream = null;
super.tearDown();
}
@@ -26,6 +38,8 @@
Context context = new ContextBase();
context.getStatusManager().add(new InfoStatus("test", this));
StatusPrinter.print(context);
+ String result = outputStream.toString();
+ assertTrue(result.contains("|-INFO in testBasic"));
}
public void testNested() {
@@ -50,7 +64,12 @@
context.getStatusManager().add(s0);
context.getStatusManager().add(s1);
context.getStatusManager().add(s2);
+
StatusPrinter.print(context);
+ String result = outputStream.toString();
+ assertTrue(result.contains("+ INFO in testNested"));
+ assertTrue(result.contains("+ WARN in testNested"));
+ assertTrue(result.contains(" |-WARN in testNested"));
}
public void testWithException() {
@@ -74,7 +93,12 @@
context.getStatusManager().add(s0);
context.getStatusManager().add(s1);
context.getStatusManager().add(s2);
- StatusPrinter.print(context);
+ StatusPrinter.print(context);
+ String result = outputStream.toString();
+ System.out.println(result);
+ assertTrue(result.contains("|-ERROR in testWithException"));
+ assertTrue(result.contains("+ INFO in testWithException"));
+ assertTrue(result.contains("ch.qos.logback.core.util.StatusPrinterTest.testWithException"));
}
}
More information about the logback-dev
mailing list