[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-86-g91aaf87
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Wed Mar 17 19:31: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 91aaf870b3817646c125f7d571118f940bf58daf (commit)
from e06bc4a748fea6af5e4878a5e411ea18d5a5fcdc (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=91aaf870b3817646c125f7d571118f940bf58daf
http://github.com/ceki/logback/commit/91aaf870b3817646c125f7d571118f940bf58daf
commit 91aaf870b3817646c125f7d571118f940bf58daf
Author: Ceki Gulcu <ceki at qos.ch>
Date: Wed Mar 17 19:29:31 2010 +0100
Applied Ruediger Dohna's patch contributed in
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 265d787..9946454 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,7 +13,6 @@
*/
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;
@@ -28,33 +27,23 @@ import ch.qos.logback.core.status.WarnStatus;
*
* @author Ceki Gülcü
* @author Tom SH Liu
+ * @author Ruediger Dohna
*/
public class ConsoleAppender<E> extends OutputStreamAppender<E> {
- public static final String SYSTEM_OUT = "System.out";
- public static final String SYSTEM_ERR = "System.err";
protected ConsoleTarget target = ConsoleTarget.SystemOut;
/**
- * As in most logback components, the default constructor does nothing.
- */
- public ConsoleAppender() {
- }
-
- /**
* Sets the value of the <b>Target</b> option. Recognized values are
* "System.out" and "System.err". Any other value will be ignored.
*/
public void setTarget(String value) {
- String v = value.trim();
-
- if (SYSTEM_OUT.equalsIgnoreCase(v)) {
- target = ConsoleTarget.SystemOut;
- } else if (SYSTEM_ERR.equalsIgnoreCase(v)) {
- target = ConsoleTarget.SystemErr;
- } else {
+ ConsoleTarget t = ConsoleTarget.findByName(value.trim());
+ if (t == null) {
targetWarn(value);
+ } else {
+ target = t;
}
}
@@ -65,26 +54,18 @@ public class ConsoleAppender<E> extends OutputStreamAppender<E> {
* See also {@link #setTarget}.
*/
public String getTarget() {
- switch (target) {
- case SystemOut:
- return SYSTEM_OUT;
- case SystemErr:
- return SYSTEM_ERR;
- }
- throw new IllegalStateException("Unexpected target value ["+target+"]");
+ return target.getName();
}
- void targetWarn(String val) {
- Status status = new WarnStatus("[" + val
- + " should be System.out or System.err.", this);
- status.add(new WarnStatus(
- "Using previously set target, System.out by default.", this));
+ 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));
addStatus(status);
}
+ @Override
public void start() {
- setOutputStream(new ConsoleOutputStreamWrapper(target));
+ setOutputStream(target.getStream());
super.start();
}
-
}
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
deleted file mode 100644
index ae53e03..0000000
--- a/logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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
index dfbcffb..ea9c30d 100644
--- 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
@@ -13,11 +13,62 @@
*/
package ch.qos.logback.core.joran.spi;
+import java.io.IOException;
+import java.io.OutputStream;
+
/**
* The set of console output targets.
*
* @author Ceki Gülcü
+ * @author Tom SH Liu
+ * @author Ruediger Dohna
*/
public enum ConsoleTarget {
- SystemOut, SystemErr;
+
+ SystemOut("System.out", new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ System.out.write(b);
+ }
+ @Override
+ public void flush() throws IOException {
+ System.out.flush();
+ }
+ }),
+
+ SystemErr("System.err", new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ System.err.write(b);
+ }
+ @Override
+ public void flush() throws IOException {
+ System.err.flush();
+ }
+ });
+
+ public static ConsoleTarget findByName(String name) {
+ for (ConsoleTarget target : ConsoleTarget.values()) {
+ if (target.name.equalsIgnoreCase(name)) {
+ return target;
+ }
+ }
+ return null;
+ }
+
+ private final String name;
+ private final OutputStream stream;
+
+ private ConsoleTarget(String name, OutputStream stream) {
+ this.name = name;
+ this.stream = stream;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public OutputStream getStream() {
+ return stream;
+ }
}
\ No newline at end of file
-----------------------------------------------------------------------
Summary of changes:
.../java/ch/qos/logback/core/ConsoleAppender.java | 41 +++--------
.../core/helpers/ConsoleOutputStreamWrapper.java | 71 --------------------
.../qos/logback/core/joran/spi/ConsoleTarget.java | 53 ++++++++++++++-
3 files changed, 63 insertions(+), 102 deletions(-)
delete mode 100644 logback-core/src/main/java/ch/qos/logback/core/helpers/ConsoleOutputStreamWrapper.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list