You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/09/04 22:48:03 UTC
git commit: Rename LoggerStreams to IoBuilder.
Repository: logging-log4j2
Updated Branches:
refs/heads/master dd945f160 -> 02e13f7d1
Rename LoggerStreams to IoBuilder.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/02e13f7d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/02e13f7d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/02e13f7d
Branch: refs/heads/master
Commit: 02e13f7d1adbef94d2f23398dc3748d0722e8c40
Parents: dd945f1
Author: Gary Gregory <ga...@gmail.com>
Authored: Thu Sep 4 16:47:59 2014 -0400
Committer: Gary Gregory <ga...@gmail.com>
Committed: Thu Sep 4 16:47:59 2014 -0400
----------------------------------------------------------------------
.../org/apache/logging/log4j/io/IoBuilder.java | 352 +++++++++++++++++++
.../logging/log4j/io/LoggerPrintWriter.java | 2 +-
.../apache/logging/log4j/io/LoggerStreams.java | 352 -------------------
.../apache/logging/log4j/io/package-info.java | 2 +-
.../io/AbstractLoggerOutputStreamTest.java | 2 +-
.../log4j/io/AbstractLoggerWriterTest.java | 2 +-
.../log4j/io/IoBuilderCallerInfoTesting.java | 55 +++
...LoggerBufferedInputStreamCallerInfoTest.java | 4 +-
.../log4j/io/LoggerBufferedInputStreamTest.java | 2 +-
.../io/LoggerBufferedReaderCallerInfoTest.java | 4 +-
.../log4j/io/LoggerBufferedReaderTest.java | 2 +-
.../log4j/io/LoggerFilterOutputStreamTest.java | 2 +-
.../log4j/io/LoggerFilterWriterTest.java | 2 +-
.../io/LoggerInputStreamCallerInfoTest.java | 4 +-
.../logging/log4j/io/LoggerInputStreamTest.java | 2 +-
.../io/LoggerOutputStreamCallerInfoTest.java | 4 +-
.../log4j/io/LoggerOutputStreamTest.java | 2 +-
.../io/LoggerPrintStreamCallerInfoTest.java | 4 +-
.../logging/log4j/io/LoggerPrintStreamTest.java | 2 +-
.../io/LoggerPrintWriterCallerInfoTest.java | 4 +-
.../log4j/io/LoggerPrintWriterJdbcH2Test.java | 2 +-
.../logging/log4j/io/LoggerPrintWriterTest.java | 2 +-
.../log4j/io/LoggerReaderCallerInfoTest.java | 4 +-
.../logging/log4j/io/LoggerReaderTest.java | 2 +-
.../io/LoggerStreamsCallerInfoTesting.java | 55 ---
.../logging/log4j/io/LoggerWriterTest.java | 2 +-
26 files changed, 436 insertions(+), 436 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/IoBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/IoBuilder.java b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/IoBuilder.java
new file mode 100644
index 0000000..9f5fb41
--- /dev/null
+++ b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/IoBuilder.java
@@ -0,0 +1,352 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.io;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LoggingException;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+
+/**
+ * Builder class to wrap {@link Logger Loggers} into Java IO compatible classes.
+ *
+ * <p>Both the {@link InputStream}/{@link OutputStream} and {@link Reader}/{@link Writer} family of classes are
+ * supported. {@link OutputStream} and {@link Writer} instances can be wrapped by a filtered version of their
+ * corresponding classes ({@link java.io.FilterOutputStream} and {@link java.io.FilterWriter}) in order to log all
+ * lines written to these instances. {@link InputStream} and {@link Reader} instances can be wrapped by a sort of
+ * wiretapped version of their respective classes; all lines read from these instances will be logged.</p>
+ *
+ * <p>The main feature, however, is the ability to create a {@link PrintWriter}, {@link PrintStream}, {@link Writer},
+ * {@link java.io.BufferedWriter}, {@link OutputStream}, or {@link java.io.BufferedOutputStream} that is backed by a
+ * {@link Logger}. The main inspiration for this feature is the JDBC API which uses a PrintWriter to perform debug
+ * logging. In order to properly integrate APIs like JDBC into Log4j, create a PrintWriter using this class.</p>
+ *
+ * <p>All IoBuilder support configuration of the logging {@link Level} it should use (defaults to the level of
+ * the underlying Logger), and an optional {@link Marker}. The other configurable objects are explained in more
+ * detail below.</p>
+ *
+ * @since 2.1
+ */
+public class IoBuilder {
+ private final ExtendedLogger logger;
+ private Level level;
+ private Marker marker;
+ private String fqcn;
+ private boolean autoFlush;
+ private boolean buffered;
+ private int bufferSize;
+ private Charset charset;
+ private Reader reader;
+ private Writer writer;
+ private InputStream inputStream;
+ private OutputStream outputStream;
+
+ /**
+ * Creates a new builder for a given {@link Logger}. The Logger instance must implement {@link ExtendedLogger} or
+ * an exception will be thrown.
+ *
+ * @param logger the Logger to wrap into a IoBuilder
+ * @return a new IoBuilder builder
+ * @throws UnsupportedOperationException if {@code logger} does not implement {@link ExtendedLogger} or if
+ * {@code logger} is {@code null}
+ */
+ public static IoBuilder forLogger(final Logger logger) {
+ return new IoBuilder(logger);
+ }
+
+ /**
+ * Creates a new builder using a Logger name. The name provided is used to get a Logger from
+ * {@link LogManager#getLogger(String)} which will be wrapped into a IoBuilder.
+ *
+ * @param loggerName the name of the Logger to wrap into a IoBuilder
+ * @return a new IoBuilder builder
+ */
+ public static IoBuilder forLogger(final String loggerName) {
+ return new IoBuilder(LogManager.getLogger(loggerName));
+ }
+
+ /**
+ * Creates a new builder using a Logger named after a given Class. The Class provided is used to get a Logger from
+ * {@link LogManager#getLogger(Class)} which will be wrapped into a IoBuilder.
+ *
+ * @param clazz the Class to use as the Logger name to wrap into a IoBuilder
+ * @return a new IoBuilder builder
+ */
+ public static IoBuilder forLogger(final Class<?> clazz) {
+ return new IoBuilder(LogManager.getLogger(clazz));
+ }
+
+ // TODO: arg-less factory (blocked by LOG4J2-809)
+
+ private IoBuilder(final Logger logger) {
+ if (!(logger instanceof ExtendedLogger)) {
+ throw new UnsupportedOperationException("The provided Logger [" + String.valueOf(logger) +
+ "] does not implement " + ExtendedLogger.class.getName());
+ }
+ this.logger = (ExtendedLogger) logger;
+ }
+
+ /**
+ * Specifies the {@link Level} to log at. If no Level is configured, then the Level of the wrapped Logger will be
+ * used.
+ *
+ * @param level the Level to use for logging
+ * @return {@code this}
+ */
+ public IoBuilder setLevel(final Level level) {
+ this.level = level;
+ return this;
+ }
+
+ /**
+ * Specifies an optional {@link Marker} to use in all logging messages. If no Marker is specified, then no Marker
+ * will be used.
+ *
+ * @param marker the Marker to associate with all logging messages
+ * @return {@code this}
+ */
+ public IoBuilder setMarker(final Marker marker) {
+ this.marker = marker;
+ return this;
+ }
+
+ // FIXME: without making this entire class more properly extensible, this field is pointless
+ public IoBuilder setWrapperClassName(final String fqcn) {
+ this.fqcn = fqcn;
+ return this;
+ }
+
+ /**
+ * Indicates whether or not a built {@link PrintWriter} or {@link PrintStream} should automatically flush when
+ * one of the {@code println}, {@code printf}, or {@code format} methods are invoked, or when a new line character
+ * is printed.
+ *
+ * @param autoFlush if {@code true}, then {@code println}, {@code printf}, and {@code format} will auto flush
+ * @return {@code this}
+ */
+ public IoBuilder setAutoFlush(final boolean autoFlush) {
+ this.autoFlush = autoFlush;
+ return this;
+ }
+
+ /**
+ * Enables or disables using a buffered variant of the desired IO class. If this is set to {@code true}, then the
+ * instances returned by {@link #buildReader()} and {@link #buildInputStream()} can be safely cast (if necessary)
+ * to {@link java.io.BufferedReader} and {@link java.io.BufferedInputStream} respectively. This option does not
+ * have any effect on the other built variants.
+ *
+ * @param buffered indicates whether or not an input IoBuilder should be buffered
+ * @return {@code this}
+ */
+ public IoBuilder setBuffered(final boolean buffered) {
+ this.buffered = buffered;
+ return this;
+ }
+
+ /**
+ * Configures the buffer size to use when building a {@link java.io.BufferedReader} or
+ * {@link java.io.BufferedInputStream} IoBuilder.
+ *
+ * @param bufferSize the buffer size to use or a non-positive integer to use the default size
+ * @return {@code this}
+ */
+ public IoBuilder setBufferSize(final int bufferSize) {
+ this.bufferSize = bufferSize;
+ return this;
+ }
+
+ /**
+ * Specifies the character set to use when building an {@link InputStream}, {@link OutputStream}, or
+ * {@link PrintStream}. If no character set is specified, then {@link java.nio.charset.Charset#defaultCharset()}
+ * is used.
+ *
+ * @param charset the character set to use when building a *Stream
+ * @return {@code this}
+ */
+ public IoBuilder setCharset(final Charset charset) {
+ this.charset = charset;
+ return this;
+ }
+
+ /**
+ * Configures a {@link Reader} to be wiretapped when building a Reader. This must be set to a non-{@code null}
+ * value in order to call {@link #buildReader()}.
+ *
+ * @param reader the Reader to wiretap
+ * @return {@code this}
+ */
+ public IoBuilder filter(final Reader reader) {
+ this.reader = reader;
+ return this;
+ }
+
+ /**
+ * Configures a {@link Writer} to be written to in addition to the underlying Logger. If no Writer is specified,
+ * then the built Writer or PrintWriter will only write to the underlying Logger.
+ *
+ * @param writer the Writer to write to in addition to the Logger
+ * @return {@code this}
+ */
+ public IoBuilder filter(final Writer writer) {
+ this.writer = writer;
+ return this;
+ }
+
+ /**
+ * Configures an {@link InputStream} to be wiretapped when building an InputStream. This must be set to a
+ * non-{@code null} value in order to call {@link #buildInputStream()}.
+ *
+ * @param inputStream the InputStream to wiretap
+ * @return {@code this}
+ */
+ public IoBuilder filter(final InputStream inputStream) {
+ this.inputStream = inputStream;
+ return this;
+ }
+
+ /**
+ * Configures an {@link OutputStream} to be written to in addition to the underlying Logger. If no OutputStream is
+ * specified, then the built OutputStream or PrintStream will only write to the underlying Logger.
+ *
+ * @param outputStream the OutputStream to write to in addition to the Logger
+ * @return {@code this}
+ */
+ public IoBuilder filter(final OutputStream outputStream) {
+ this.outputStream = outputStream;
+ return this;
+ }
+
+ /**
+ * Builds a new {@link Reader} that is wiretapped by its underlying Logger. If buffering is enabled, then a
+ * {@link java.io.BufferedReader} will be returned.
+ *
+ * @return a new Reader wiretapped by a Logger
+ * @throws IllegalStateException if no Reader was configured for this builder
+ */
+ public Reader buildReader() {
+ final Reader in = requireNonNull(this.reader, "reader");
+ if (this.buffered) {
+ if (this.bufferSize > 0) {
+ return new LoggerBufferedReader(in, this.bufferSize, this.logger, this.fqcn, this.level, this.marker);
+ }
+ return new LoggerBufferedReader(in, this.logger, this.fqcn, this.level, this.marker);
+ }
+ return new LoggerReader(in, this.logger, this.fqcn, this.level, this.marker);
+ }
+
+ /**
+ * Builds a new {@link Writer} that is backed by a Logger and optionally writes to another Writer as well. If no
+ * Writer is configured for this builder, then the returned Writer will only write to its underlying Logger.
+ *
+ * @return a new Writer or {@link java.io.FilterWriter} backed by a Logger
+ */
+ public Writer buildWriter() {
+ if (this.writer == null) {
+ return new LoggerWriter(this.logger, this.fqcn, this.level, this.marker);
+ }
+ return new LoggerFilterWriter(this.writer, this.logger, this.fqcn, this.level, this.marker);
+ }
+
+ /**
+ * Builds a new {@link PrintWriter} that is backed by a Logger and optionally writes to another Writer as well. If
+ * no Writer is configured for this builder, then the returned PrintWriter will only write to its underlying
+ * Logger.
+ *
+ * @return a new PrintWriter that optionally writes to another Writer in addition to its underlying Logger
+ */
+ public PrintWriter buildPrintWriter() {
+ if (this.writer == null) {
+ return new LoggerPrintWriter(this.logger, this.autoFlush, this.fqcn, this.level, this.marker);
+ }
+ return new LoggerPrintWriter(this.writer, this.autoFlush, this.logger, this.fqcn, this.level, this.marker);
+ }
+
+ /**
+ * Builds a new {@link InputStream} that is wiretapped by its underlying Logger. If buffering is enabled, then a
+ * {@link java.io.BufferedInputStream} will be returned.
+ *
+ * @return a new InputStream wiretapped by a Logger
+ * @throws IllegalStateException if no InputStream was configured for this builder
+ */
+ public InputStream buildInputStream() {
+ final InputStream in = requireNonNull(this.inputStream, "inputStream");
+ if (this.buffered) {
+ if (this.bufferSize > 0) {
+ return new LoggerBufferedInputStream(in, this.charset, this.bufferSize, this.logger, this.fqcn,
+ this.level, this.marker);
+ }
+ return new LoggerBufferedInputStream(in, this.charset, this.logger, this.fqcn, this.level, this.marker);
+ }
+ return new LoggerInputStream(in, this.charset, this.logger, this.fqcn, this.level, this.marker);
+ }
+
+ /**
+ * Builds a new {@link OutputStream} that is backed by a Logger and optionally writes to another OutputStream as
+ * well. If no OutputStream is configured for this builder, then the returned OutputStream will only write to its
+ * underlying Logger.
+ *
+ * @return a new OutputStream that optionally writes to another OutputStream in addition to its underlying Logger
+ */
+ public OutputStream buildOutputStream() {
+ if (this.outputStream == null) {
+ return new LoggerOutputStream(this.logger, this.level, this.marker, this.charset, this.fqcn);
+ }
+ return new LoggerFilterOutputStream(this.outputStream, this.charset, this.logger, this.fqcn, this.level,
+ this.marker);
+ }
+
+ /**
+ * Builds a new {@link PrintStream} that is backed by a Logger and optionally writes to another OutputStream as
+ * well. If no OutputStream is configured for this builder, then the returned PrintStream will only write to its
+ * underlying Logger.
+ *
+ * @return a new PrintStream that optionally writes to another OutputStream in addition to its underlying Logger
+ * @throws LoggingException if the configured character set is unsupported by {@link PrintStream}
+ */
+ public PrintStream buildPrintStream() {
+ try {
+ if (this.outputStream == null) {
+ return new LoggerPrintStream(this.logger, this.autoFlush, this.charset, this.fqcn, this.level,
+ this.marker);
+ }
+ return new LoggerPrintStream(this.outputStream, this.autoFlush, this.charset, this.logger, this.fqcn,
+ this.level, this.marker);
+ } catch (final UnsupportedEncodingException e) {
+ // this exception shouldn't really happen since we use Charset and not String
+ throw new LoggingException(e);
+ }
+ }
+
+ private static <T> T requireNonNull(final T obj, final String name) {
+ if (obj == null) {
+ throw new IllegalStateException("The property " + name + " was not set");
+ }
+ return obj;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerPrintWriter.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerPrintWriter.java b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerPrintWriter.java
index ef5ed55..d9b0c35 100644
--- a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerPrintWriter.java
+++ b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerPrintWriter.java
@@ -33,7 +33,7 @@ import org.apache.logging.log4j.spi.ExtendedLogger;
* </p>
* <pre>
* Logger logger = LogManager.getLogger();
- * PrintWriter pw = LoggerStreams.forLogger(logger).setLevel(Level.DEBUG).buildPrintWriter();
+ * PrintWriter pw = IoBuilder.forLogger(logger).setLevel(Level.DEBUG).buildPrintWriter();
* DriverManager.setLogWriter(pw);
* DataSource ds = ...
* ds.setLogWriter(pw);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerStreams.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerStreams.java b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerStreams.java
deleted file mode 100644
index 83560af..0000000
--- a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/LoggerStreams.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * 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.
- */
-package org.apache.logging.log4j.io;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LoggingException;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.spi.ExtendedLogger;
-
-/**
- * Builder class to wrap {@link Logger Loggers} into Java IO compatible classes.
- *
- * <p>Both the {@link InputStream}/{@link OutputStream} and {@link Reader}/{@link Writer} family of classes are
- * supported. {@link OutputStream} and {@link Writer} instances can be wrapped by a filtered version of their
- * corresponding classes ({@link java.io.FilterOutputStream} and {@link java.io.FilterWriter}) in order to log all
- * lines written to these instances. {@link InputStream} and {@link Reader} instances can be wrapped by a sort of
- * wiretapped version of their respective classes; all lines read from these instances will be logged.</p>
- *
- * <p>The main feature, however, is the ability to create a {@link PrintWriter}, {@link PrintStream}, {@link Writer},
- * {@link java.io.BufferedWriter}, {@link OutputStream}, or {@link java.io.BufferedOutputStream} that is backed by a
- * {@link Logger}. The main inspiration for this feature is the JDBC API which uses a PrintWriter to perform debug
- * logging. In order to properly integrate APIs like JDBC into Log4j, create a PrintWriter using this class.</p>
- *
- * <p>All LoggerStreams support configuration of the logging {@link Level} it should use (defaults to the level of
- * the underlying Logger), and an optional {@link Marker}. The other configurable objects are explained in more
- * detail below.</p>
- *
- * @since 2.1
- */
-public class LoggerStreams {
- private final ExtendedLogger logger;
- private Level level;
- private Marker marker;
- private String fqcn;
- private boolean autoFlush;
- private boolean buffered;
- private int bufferSize;
- private Charset charset;
- private Reader reader;
- private Writer writer;
- private InputStream inputStream;
- private OutputStream outputStream;
-
- /**
- * Creates a new builder for a given {@link Logger}. The Logger instance must implement {@link ExtendedLogger} or
- * an exception will be thrown.
- *
- * @param logger the Logger to wrap into a LoggerStream
- * @return a new LoggerStream builder
- * @throws UnsupportedOperationException if {@code logger} does not implement {@link ExtendedLogger} or if
- * {@code logger} is {@code null}
- */
- public static LoggerStreams forLogger(final Logger logger) {
- return new LoggerStreams(logger);
- }
-
- /**
- * Creates a new builder using a Logger name. The name provided is used to get a Logger from
- * {@link LogManager#getLogger(String)} which will be wrapped into a LoggerStream.
- *
- * @param loggerName the name of the Logger to wrap into a LoggerStream
- * @return a new LoggerStream builder
- */
- public static LoggerStreams forLogger(final String loggerName) {
- return new LoggerStreams(LogManager.getLogger(loggerName));
- }
-
- /**
- * Creates a new builder using a Logger named after a given Class. The Class provided is used to get a Logger from
- * {@link LogManager#getLogger(Class)} which will be wrapped into a LoggerStream.
- *
- * @param clazz the Class to use as the Logger name to wrap into a LoggerStream
- * @return a new LoggerStream builder
- */
- public static LoggerStreams forLogger(final Class<?> clazz) {
- return new LoggerStreams(LogManager.getLogger(clazz));
- }
-
- // TODO: arg-less factory (blocked by LOG4J2-809)
-
- private LoggerStreams(final Logger logger) {
- if (!(logger instanceof ExtendedLogger)) {
- throw new UnsupportedOperationException("The provided Logger [" + String.valueOf(logger) +
- "] does not implement " + ExtendedLogger.class.getName());
- }
- this.logger = (ExtendedLogger) logger;
- }
-
- /**
- * Specifies the {@link Level} to log at. If no Level is configured, then the Level of the wrapped Logger will be
- * used.
- *
- * @param level the Level to use for logging
- * @return {@code this}
- */
- public LoggerStreams setLevel(final Level level) {
- this.level = level;
- return this;
- }
-
- /**
- * Specifies an optional {@link Marker} to use in all logging messages. If no Marker is specified, then no Marker
- * will be used.
- *
- * @param marker the Marker to associate with all logging messages
- * @return {@code this}
- */
- public LoggerStreams setMarker(final Marker marker) {
- this.marker = marker;
- return this;
- }
-
- // FIXME: without making this entire class more properly extensible, this field is pointless
- public LoggerStreams setWrapperClassName(final String fqcn) {
- this.fqcn = fqcn;
- return this;
- }
-
- /**
- * Indicates whether or not a built {@link PrintWriter} or {@link PrintStream} should automatically flush when
- * one of the {@code println}, {@code printf}, or {@code format} methods are invoked, or when a new line character
- * is printed.
- *
- * @param autoFlush if {@code true}, then {@code println}, {@code printf}, and {@code format} will auto flush
- * @return {@code this}
- */
- public LoggerStreams setAutoFlush(final boolean autoFlush) {
- this.autoFlush = autoFlush;
- return this;
- }
-
- /**
- * Enables or disables using a buffered variant of the desired IO class. If this is set to {@code true}, then the
- * instances returned by {@link #buildReader()} and {@link #buildInputStream()} can be safely cast (if necessary)
- * to {@link java.io.BufferedReader} and {@link java.io.BufferedInputStream} respectively. This option does not
- * have any effect on the other built variants.
- *
- * @param buffered indicates whether or not an input LoggerStream should be buffered
- * @return {@code this}
- */
- public LoggerStreams setBuffered(final boolean buffered) {
- this.buffered = buffered;
- return this;
- }
-
- /**
- * Configures the buffer size to use when building a {@link java.io.BufferedReader} or
- * {@link java.io.BufferedInputStream} LoggerStream.
- *
- * @param bufferSize the buffer size to use or a non-positive integer to use the default size
- * @return {@code this}
- */
- public LoggerStreams setBufferSize(final int bufferSize) {
- this.bufferSize = bufferSize;
- return this;
- }
-
- /**
- * Specifies the character set to use when building an {@link InputStream}, {@link OutputStream}, or
- * {@link PrintStream}. If no character set is specified, then {@link java.nio.charset.Charset#defaultCharset()}
- * is used.
- *
- * @param charset the character set to use when building a *Stream
- * @return {@code this}
- */
- public LoggerStreams setCharset(final Charset charset) {
- this.charset = charset;
- return this;
- }
-
- /**
- * Configures a {@link Reader} to be wiretapped when building a Reader. This must be set to a non-{@code null}
- * value in order to call {@link #buildReader()}.
- *
- * @param reader the Reader to wiretap
- * @return {@code this}
- */
- public LoggerStreams filter(final Reader reader) {
- this.reader = reader;
- return this;
- }
-
- /**
- * Configures a {@link Writer} to be written to in addition to the underlying Logger. If no Writer is specified,
- * then the built Writer or PrintWriter will only write to the underlying Logger.
- *
- * @param writer the Writer to write to in addition to the Logger
- * @return {@code this}
- */
- public LoggerStreams filter(final Writer writer) {
- this.writer = writer;
- return this;
- }
-
- /**
- * Configures an {@link InputStream} to be wiretapped when building an InputStream. This must be set to a
- * non-{@code null} value in order to call {@link #buildInputStream()}.
- *
- * @param inputStream the InputStream to wiretap
- * @return {@code this}
- */
- public LoggerStreams filter(final InputStream inputStream) {
- this.inputStream = inputStream;
- return this;
- }
-
- /**
- * Configures an {@link OutputStream} to be written to in addition to the underlying Logger. If no OutputStream is
- * specified, then the built OutputStream or PrintStream will only write to the underlying Logger.
- *
- * @param outputStream the OutputStream to write to in addition to the Logger
- * @return {@code this}
- */
- public LoggerStreams filter(final OutputStream outputStream) {
- this.outputStream = outputStream;
- return this;
- }
-
- /**
- * Builds a new {@link Reader} that is wiretapped by its underlying Logger. If buffering is enabled, then a
- * {@link java.io.BufferedReader} will be returned.
- *
- * @return a new Reader wiretapped by a Logger
- * @throws IllegalStateException if no Reader was configured for this builder
- */
- public Reader buildReader() {
- final Reader in = requireNonNull(this.reader, "reader");
- if (this.buffered) {
- if (this.bufferSize > 0) {
- return new LoggerBufferedReader(in, this.bufferSize, this.logger, this.fqcn, this.level, this.marker);
- }
- return new LoggerBufferedReader(in, this.logger, this.fqcn, this.level, this.marker);
- }
- return new LoggerReader(in, this.logger, this.fqcn, this.level, this.marker);
- }
-
- /**
- * Builds a new {@link Writer} that is backed by a Logger and optionally writes to another Writer as well. If no
- * Writer is configured for this builder, then the returned Writer will only write to its underlying Logger.
- *
- * @return a new Writer or {@link java.io.FilterWriter} backed by a Logger
- */
- public Writer buildWriter() {
- if (this.writer == null) {
- return new LoggerWriter(this.logger, this.fqcn, this.level, this.marker);
- }
- return new LoggerFilterWriter(this.writer, this.logger, this.fqcn, this.level, this.marker);
- }
-
- /**
- * Builds a new {@link PrintWriter} that is backed by a Logger and optionally writes to another Writer as well. If
- * no Writer is configured for this builder, then the returned PrintWriter will only write to its underlying
- * Logger.
- *
- * @return a new PrintWriter that optionally writes to another Writer in addition to its underlying Logger
- */
- public PrintWriter buildPrintWriter() {
- if (this.writer == null) {
- return new LoggerPrintWriter(this.logger, this.autoFlush, this.fqcn, this.level, this.marker);
- }
- return new LoggerPrintWriter(this.writer, this.autoFlush, this.logger, this.fqcn, this.level, this.marker);
- }
-
- /**
- * Builds a new {@link InputStream} that is wiretapped by its underlying Logger. If buffering is enabled, then a
- * {@link java.io.BufferedInputStream} will be returned.
- *
- * @return a new InputStream wiretapped by a Logger
- * @throws IllegalStateException if no InputStream was configured for this builder
- */
- public InputStream buildInputStream() {
- final InputStream in = requireNonNull(this.inputStream, "inputStream");
- if (this.buffered) {
- if (this.bufferSize > 0) {
- return new LoggerBufferedInputStream(in, this.charset, this.bufferSize, this.logger, this.fqcn,
- this.level, this.marker);
- }
- return new LoggerBufferedInputStream(in, this.charset, this.logger, this.fqcn, this.level, this.marker);
- }
- return new LoggerInputStream(in, this.charset, this.logger, this.fqcn, this.level, this.marker);
- }
-
- /**
- * Builds a new {@link OutputStream} that is backed by a Logger and optionally writes to another OutputStream as
- * well. If no OutputStream is configured for this builder, then the returned OutputStream will only write to its
- * underlying Logger.
- *
- * @return a new OutputStream that optionally writes to another OutputStream in addition to its underlying Logger
- */
- public OutputStream buildOutputStream() {
- if (this.outputStream == null) {
- return new LoggerOutputStream(this.logger, this.level, this.marker, this.charset, this.fqcn);
- }
- return new LoggerFilterOutputStream(this.outputStream, this.charset, this.logger, this.fqcn, this.level,
- this.marker);
- }
-
- /**
- * Builds a new {@link PrintStream} that is backed by a Logger and optionally writes to another OutputStream as
- * well. If no OutputStream is configured for this builder, then the returned PrintStream will only write to its
- * underlying Logger.
- *
- * @return a new PrintStream that optionally writes to another OutputStream in addition to its underlying Logger
- * @throws LoggingException if the configured character set is unsupported by {@link PrintStream}
- */
- public PrintStream buildPrintStream() {
- try {
- if (this.outputStream == null) {
- return new LoggerPrintStream(this.logger, this.autoFlush, this.charset, this.fqcn, this.level,
- this.marker);
- }
- return new LoggerPrintStream(this.outputStream, this.autoFlush, this.charset, this.logger, this.fqcn,
- this.level, this.marker);
- } catch (final UnsupportedEncodingException e) {
- // this exception shouldn't really happen since we use Charset and not String
- throw new LoggingException(e);
- }
- }
-
- private static <T> T requireNonNull(final T obj, final String name) {
- if (obj == null) {
- throw new IllegalStateException("The property " + name + " was not set");
- }
- return obj;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/package-info.java b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/package-info.java
index ea0d6ff..ab09b75 100644
--- a/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/package-info.java
+++ b/log4j-iostreams/src/main/java/org/apache/logging/log4j/io/package-info.java
@@ -15,6 +15,6 @@
* limitations under the license.
*/
/**
- * TODO: introduction to LoggerStreams
+ * TODO: introduction to IoBuilder
*/
package org.apache.logging.log4j.io;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerOutputStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerOutputStreamTest.java
index d0f82e2..2307d3f 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerOutputStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerOutputStreamTest.java
@@ -70,7 +70,7 @@ public abstract class AbstractLoggerOutputStreamTest extends AbstractStreamTest
replay(out);
final OutputStream filteredOut =
- LoggerStreams.forLogger(getExtendedLogger())
+ IoBuilder.forLogger(getExtendedLogger())
.filter(out)
.setLevel(LEVEL)
.buildOutputStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerWriterTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerWriterTest.java
index 9cc0fbb..8766290 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerWriterTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/AbstractLoggerWriterTest.java
@@ -71,7 +71,7 @@ public abstract class AbstractLoggerWriterTest extends AbstractStreamTest {
replay(out);
final OutputStream filteredOut =
- LoggerStreams.forLogger(getExtendedLogger())
+ IoBuilder.forLogger(getExtendedLogger())
.filter(out)
.setLevel(LEVEL)
.buildOutputStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
new file mode 100644
index 0000000..6db45b1
--- /dev/null
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/IoBuilderCallerInfoTesting.java
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.io;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.Before;
+import org.junit.ClassRule;
+
+import static org.junit.Assert.*;
+
+public class IoBuilderCallerInfoTesting {
+
+ protected static Logger getExtendedLogger() {
+ return ctx.getLogger("ClassAndMethodLogger");
+ }
+
+ protected static Logger getLogger() {
+ return getExtendedLogger();
+ }
+
+ protected final static Level LEVEL = Level.WARN;
+
+ @ClassRule
+ public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml");
+
+ public void assertMessages(final String msg, final int size, final String methodName) {
+ final ListAppender appender = ctx.getListAppender("ClassAndMethod");
+ assertEquals(msg + ".size", size, appender.getMessages().size());
+ for (final String message : appender.getMessages()) {
+ assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
+ }
+ }
+
+ @Before
+ public void clearAppender() {
+ ctx.getListAppender("ClassAndMethod").clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamCallerInfoTest.java
index 2822c89..5975407 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamCallerInfoTest.java
@@ -23,7 +23,7 @@ import java.io.InputStream;
import org.junit.Before;
import org.junit.Test;
-public class LoggerBufferedInputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerBufferedInputStreamCallerInfoTest extends IoBuilderCallerInfoTesting {
private BufferedInputStream logIn;
@@ -63,7 +63,7 @@ public class LoggerBufferedInputStreamCallerInfoTest extends LoggerStreamsCaller
public void setupStreams() {
final InputStream srcInputStream = new ByteArrayInputStream("a\nb\nc\nd".getBytes());
this.logIn = (BufferedInputStream)
- LoggerStreams.forLogger(getLogger())
+ IoBuilder.forLogger(getLogger())
.filter(srcInputStream)
.setLevel(LEVEL)
.setBuffered(true)
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamTest.java
index dc1add2..79b4d5d 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedInputStreamTest.java
@@ -24,7 +24,7 @@ public class LoggerBufferedInputStreamTest extends LoggerInputStreamTest {
@Override
protected InputStream createInputStream() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(Level.ERROR)
.setBuffered(true)
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderCallerInfoTest.java
index bd07f6d..6f83dbb 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderCallerInfoTest.java
@@ -25,7 +25,7 @@ import org.apache.logging.log4j.Level;
import org.junit.Before;
import org.junit.Test;
-public class LoggerBufferedReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerBufferedReaderCallerInfoTest extends IoBuilderCallerInfoTesting {
BufferedReader logReader;
@@ -81,7 +81,7 @@ public class LoggerBufferedReaderCallerInfoTest extends LoggerStreamsCallerInfoT
public void setupReader() {
final Reader srcReader = new StringReader("a\nb\nc\nd");
this.logReader = (BufferedReader)
- LoggerStreams.forLogger(getLogger())
+ IoBuilder.forLogger(getLogger())
.filter(srcReader)
.setLevel(Level.WARN)
.setBuffered(true)
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderTest.java
index 88e5a03..932e571 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerBufferedReaderTest.java
@@ -29,7 +29,7 @@ public class LoggerBufferedReaderTest extends LoggerReaderTest {
@Override
protected Reader createReader() {
return this.bufferedReader = (BufferedReader)
- LoggerStreams.forLogger(getExtendedLogger())
+ IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.setBuffered(true)
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterOutputStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterOutputStreamTest.java
index 95f637b..80bf5e3 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterOutputStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterOutputStreamTest.java
@@ -30,7 +30,7 @@ public class LoggerFilterOutputStreamTest extends AbstractLoggerOutputStreamTest
@Override
protected OutputStream createOutputStreamWrapper() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(Level.ERROR)
.buildOutputStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterWriterTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterWriterTest.java
index dbde900..5ca48c6 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterWriterTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerFilterWriterTest.java
@@ -12,7 +12,7 @@ public class LoggerFilterWriterTest extends AbstractLoggerWriterTest {
@Override
protected Writer createWriterWrapper() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.buildWriter();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamCallerInfoTest.java
index 690352e..36f70f3 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamCallerInfoTest.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Level;
import org.junit.Before;
import org.junit.Test;
-public class LoggerInputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerInputStreamCallerInfoTest extends IoBuilderCallerInfoTesting {
private InputStream logIn;
@@ -49,7 +49,7 @@ public class LoggerInputStreamCallerInfoTest extends LoggerStreamsCallerInfoTest
@Before
public void setupStreams() {
final InputStream srcInputStream = new ByteArrayInputStream("a\nb\nc\nd".getBytes());
- this.logIn = LoggerStreams.forLogger(getLogger())
+ this.logIn = IoBuilder.forLogger(getLogger())
.filter(srcInputStream)
.setLevel(Level.WARN)
.buildInputStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamTest.java
index f0c6d48..9242eef 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerInputStreamTest.java
@@ -33,7 +33,7 @@ public class LoggerInputStreamTest extends AbstractStreamTest {
protected InputStream in;
protected InputStream createInputStream() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.buildInputStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamCallerInfoTest.java
index cee3952..1b5eb85 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamCallerInfoTest.java
@@ -22,13 +22,13 @@ import org.apache.logging.log4j.Level;
import org.junit.Before;
import org.junit.Test;
-public class LoggerOutputStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerOutputStreamCallerInfoTest extends IoBuilderCallerInfoTesting {
private OutputStream logOut;
@Before
public void setupStreams() {
- this.logOut = LoggerStreams.forLogger(getExtendedLogger()).setLevel(Level.WARN).buildOutputStream();
+ this.logOut = IoBuilder.forLogger(getExtendedLogger()).setLevel(Level.WARN).buildOutputStream();
}
@Test
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamTest.java
index 42f752c..915d2cb 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerOutputStreamTest.java
@@ -30,7 +30,7 @@ public class LoggerOutputStreamTest extends AbstractLoggerOutputStreamTest {
@Override
protected OutputStream createOutputStreamWrapper() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.setLevel(Level.ERROR)
.buildOutputStream();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamCallerInfoTest.java
index 84197e8..723336f 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamCallerInfoTest.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Level;
import org.junit.Before;
import org.junit.Test;
-public class LoggerPrintStreamCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerPrintStreamCallerInfoTest extends IoBuilderCallerInfoTesting {
private PrintStream logOut;
@@ -121,7 +121,7 @@ public class LoggerPrintStreamCallerInfoTest extends LoggerStreamsCallerInfoTest
@Before
public void setupStreams() {
- this.logOut = LoggerStreams.forLogger(getLogger())
+ this.logOut = IoBuilder.forLogger(getLogger())
.setLevel(Level.WARN)
.buildPrintStream();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamTest.java
index 37cea4e..fca51f1 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintStreamTest.java
@@ -34,7 +34,7 @@ public class LoggerPrintStreamTest extends AbstractLoggerOutputStreamTest {
@Override
protected OutputStream createOutputStreamWrapper() {
- return this.print = LoggerStreams.forLogger(getExtendedLogger())
+ return this.print = IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.buildPrintStream();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterCallerInfoTest.java
index 416b44d..ca6ce01 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterCallerInfoTest.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Level;
import org.junit.Before;
import org.junit.Test;
-public class LoggerPrintWriterCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerPrintWriterCallerInfoTest extends IoBuilderCallerInfoTesting {
private PrintWriter logOut;
@@ -121,7 +121,7 @@ public class LoggerPrintWriterCallerInfoTest extends LoggerStreamsCallerInfoTest
@Before
public void setupStreams() {
- this.logOut = LoggerStreams.forLogger(getLogger())
+ this.logOut = IoBuilder.forLogger(getLogger())
.setLevel(Level.WARN)
.buildPrintWriter();
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
index d49b446..53a7d5b 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterJdbcH2Test.java
@@ -29,7 +29,7 @@ public class LoggerPrintWriterJdbcH2Test {
private ListAppender listAppender;
private PrintWriter createLoggerPrintWriter() {
- return LoggerStreams.forLogger(context.getLogger()).setLevel(Level.ALL).buildPrintWriter();
+ return IoBuilder.forLogger(context.getLogger()).setLevel(Level.ALL).buildPrintWriter();
}
private ListAppender getListAppender() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterTest.java
index 3559c75..032e004 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerPrintWriterTest.java
@@ -35,7 +35,7 @@ public class LoggerPrintWriterTest extends AbstractLoggerWriterTest {
@Override
protected Writer createWriterWrapper() {
this.print =
- LoggerStreams.forLogger(getExtendedLogger())
+ IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.buildPrintWriter();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderCallerInfoTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderCallerInfoTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderCallerInfoTest.java
index f084234..ae009b2 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderCallerInfoTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderCallerInfoTest.java
@@ -23,7 +23,7 @@ import java.nio.CharBuffer;
import org.junit.Before;
import org.junit.Test;
-public class LoggerReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting {
+public class LoggerReaderCallerInfoTest extends IoBuilderCallerInfoTesting {
Reader logReader;
@@ -52,7 +52,7 @@ public class LoggerReaderCallerInfoTest extends LoggerStreamsCallerInfoTesting {
@Before
public void setupReader() {
final Reader srcReader = new StringReader("a\nb\nc\nd\ne");
- this.logReader = LoggerStreams.forLogger(getLogger())
+ this.logReader = IoBuilder.forLogger(getLogger())
.filter(srcReader)
.setLevel(LEVEL)
.buildReader();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderTest.java
index 10d715f..b6383e2 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerReaderTest.java
@@ -34,7 +34,7 @@ public class LoggerReaderTest extends AbstractStreamTest {
protected Reader reader;
protected Reader createReader() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.filter(this.wrapped)
.setLevel(LEVEL)
.buildReader();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerStreamsCallerInfoTesting.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerStreamsCallerInfoTesting.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerStreamsCallerInfoTesting.java
deleted file mode 100644
index 58f6fa0..0000000
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerStreamsCallerInfoTesting.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.
- */
-package org.apache.logging.log4j.io;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.junit.InitialLoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
-import org.junit.Before;
-import org.junit.ClassRule;
-
-import static org.junit.Assert.*;
-
-public class LoggerStreamsCallerInfoTesting {
-
- protected static Logger getExtendedLogger() {
- return ctx.getLogger("ClassAndMethodLogger");
- }
-
- protected static Logger getLogger() {
- return getExtendedLogger();
- }
-
- protected final static Level LEVEL = Level.WARN;
-
- @ClassRule
- public static InitialLoggerContext ctx = new InitialLoggerContext("log4j2-streams-calling-info.xml");
-
- public void assertMessages(final String msg, final int size, final String methodName) {
- final ListAppender appender = ctx.getListAppender("ClassAndMethod");
- assertEquals(msg + ".size", size, appender.getMessages().size());
- for (final String message : appender.getMessages()) {
- assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
- }
- }
-
- @Before
- public void clearAppender() {
- ctx.getListAppender("ClassAndMethod").clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/02e13f7d/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerWriterTest.java
----------------------------------------------------------------------
diff --git a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerWriterTest.java b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerWriterTest.java
index 0a302aa..21f2fb7 100644
--- a/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerWriterTest.java
+++ b/log4j-iostreams/src/test/java/org/apache/logging/log4j/io/LoggerWriterTest.java
@@ -28,7 +28,7 @@ public class LoggerWriterTest extends AbstractLoggerWriterTest {
@Override
protected Writer createWriterWrapper() {
- return LoggerStreams.forLogger(getExtendedLogger())
+ return IoBuilder.forLogger(getExtendedLogger())
.setLevel(LEVEL)
.buildWriter();
}