[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-83-g3faa7d8
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Wed Mar 17 10:22:03 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 3faa7d8bc517251201915d2add3e2f86cc25a649 (commit)
from df1f63a50268df0d6a9a9dcf352f4abc8766c74f (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=3faa7d8bc517251201915d2add3e2f86cc25a649
http://github.com/ceki/logback/commit/3faa7d8bc517251201915d2add3e2f86cc25a649
commit 3faa7d8bc517251201915d2add3e2f86cc25a649
Author: Ceki Gulcu <ceki at qos.ch>
Date: Wed Mar 17 10:21:10 2010 +0100
Fixed http://jira.qos.ch/browse/LBCORE-143
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 5304874..265d787 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 ch.qos.logback.core.helpers.ConsoleOutputStreamWrapper;
+import ch.qos.logback.core.joran.spi.ConsoleTarget;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.WarnStatus;
@@ -25,13 +27,14 @@ import ch.qos.logback.core.status.WarnStatus;
* at http://logback.qos.ch/manual/appenders.html#ConsoleAppender
*
* @author Ceki Gülcü
+ * @author Tom SH Liu
*/
public class ConsoleAppender<E> extends OutputStreamAppender<E> {
public static final String SYSTEM_OUT = "System.out";
public static final String SYSTEM_ERR = "System.err";
- protected String target = SYSTEM_OUT;
+ protected ConsoleTarget target = ConsoleTarget.SystemOut;
/**
* As in most logback components, the default constructor does nothing.
@@ -47,22 +50,28 @@ public class ConsoleAppender<E> extends OutputStreamAppender<E> {
String v = value.trim();
if (SYSTEM_OUT.equalsIgnoreCase(v)) {
- target = SYSTEM_OUT;
+ target = ConsoleTarget.SystemOut;
} else if (SYSTEM_ERR.equalsIgnoreCase(v)) {
- target = SYSTEM_ERR;
+ target = ConsoleTarget.SystemErr;
} else {
targetWarn(value);
}
}
/**
- * Returns the current value of the <b>Target</b> property. The default value
+ * Returns the current value of the <b>target</b> property. The default value
* of the option is "System.out".
*
* See also {@link #setTarget}.
*/
public String getTarget() {
- return target;
+ switch (target) {
+ case SystemOut:
+ return SYSTEM_OUT;
+ case SystemErr:
+ return SYSTEM_ERR;
+ }
+ throw new IllegalStateException("Unexpected target value ["+target+"]");
}
void targetWarn(String val) {
@@ -74,22 +83,8 @@ public class ConsoleAppender<E> extends OutputStreamAppender<E> {
}
public void start() {
- if (target.equals(SYSTEM_OUT)) {
- setOutputStream(System.out);
- } else {
- setOutputStream(System.err);
- }
+ setOutputStream(new ConsoleOutputStreamWrapper(target));
super.start();
}
- /**
- * This method overrides the parent
- * {@link OutputStreamAppender#closeOutputStream} implementation because the
- * console stream is not ours to close.
- */
- @Override
- protected final void closeOutputStream() {
- encoderClose();
- }
-
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java b/logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java
new file mode 100644
index 0000000..ae53e03
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java
@@ -0,0 +1,71 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under either
+ * the terms of the Eclipse Public License v1.0 as published by the Eclipse
+ * Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.helpers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import ch.qos.logback.core.joran.spi.ConsoleTarget;
+
+/**
+ * An {@link OutputStream} which always outputs to the current value of
+ * System.out/System.err.
+ *
+ * @author Ceki Gülcü
+ * @author Tom SH Liu
+ */
+public class ConsoleOutputStreamWrapper extends OutputStream {
+
+ ConsoleTarget consoleTarget;
+
+ public ConsoleOutputStreamWrapper(ConsoleTarget consoleTarget) {
+ this.consoleTarget = consoleTarget;
+ }
+
+ private OutputStream getOutputStream() {
+ switch (consoleTarget) {
+ case SystemOut:
+ return System.out;
+ case SystemErr:
+ return System.err;
+ }
+ throw new IllegalStateException("Unpexpected consoleTarget value ["
+ + consoleTarget + "]");
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ getOutputStream().write(b);
+ }
+
+ @Override
+ public void write(byte b[]) throws IOException {
+ this.write(b, 0, b.length);
+ }
+
+ @Override
+ public void write(byte b[], int off, int len) throws IOException {
+ getOutputStream().write(b, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ getOutputStream().flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ // the console is not ours to close
+ }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConsoleTarget.java b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConsoleTarget.java
new file mode 100644
index 0000000..dfbcffb
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConsoleTarget.java
@@ -0,0 +1,23 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under either
+ * the terms of the Eclipse Public License v1.0 as published by the Eclipse
+ * Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.joran.spi;
+
+/**
+ * The set of console output targets.
+ *
+ * @author Ceki Gülcü
+ */
+public enum ConsoleTarget {
+ SystemOut, SystemErr;
+}
\ No newline at end of file
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 bce6931..e8e015c 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
@@ -27,6 +27,7 @@ import ch.qos.logback.core.Appender;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.CoreConstants;
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;
@@ -105,6 +106,21 @@ public class ConsoleAppenderTest extends AbstractAppenderTest<Object> {
assertEquals(DummyLayout.DUMMY + "CLOSED", tee.toString());
}
+ // See http://jira.qos.ch/browse/LBCORE-143
+ @Test
+ public void changeInConsole() {
+ ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
+ EchoEncoder<Object> encoder = new EchoEncoder<Object>();
+ ca.setEncoder(encoder);
+ ca.start();
+ ca.doAppend("a");
+ 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());
+ }
@Test
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 7a7be5a..1deacc2 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -109,8 +109,18 @@
href="http://jira.qos.ch/browse/LBCLASSIC-194">LBCLASSIC-194</a>.
</p>
+ <p>Instead of sending its output to the System.out/err reference
+ that was effective at initialization, <code>ConsoleAppender</code>
+ will now seek the most current System.out/err reference and send
+ its output there. This fixes <a
+ href="http://jira.qos.ch/browse/LBCORE-143">LBCORE-143</a> as
+ reported by Tom SH Liu.
+ </p>
+
<hr width="80%" align="center" />
+ <!-- ======================================================================== -->
+
<h3>3rd of December 2009 - Release of version 0.9.18</h3>
<p>After a very long investigation resulting in somewhat a better
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/core/ConsoleAppender.java | 35 ++++------
.../core/helpers/ConsoleOutputStreamWrapper.java | 71 ++++++++++++++++++++
.../qos/logback/core/joran/spi/ConsoleTarget.java | 23 ++++++
.../logback/core/appender/ConsoleAppenderTest.java | 16 +++++
logback-site/src/site/pages/news.html | 10 +++
5 files changed, 135 insertions(+), 20 deletions(-)
create mode 100644 logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java
create mode 100644 logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConsoleTarget.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list