From fc722bff22a3857d7edd97887ab10d279e586486 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 21 Mar 2020 13:51:42 -0500 Subject: [PATCH] Issue #4620 - support alt PrintStream in StdErrAppender properly + The console-capture jetty module will reset System.err to RollingFileOutputStream. But that's too late, as StdErrAppender has already grabbed and is holding onto the System.err from earlier, which means it is not writing to the new System.err. Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/logging/StdErrAppender.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java index 001a30554613..b851e76a4dd9 100644 --- a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/StdErrAppender.java @@ -57,11 +57,11 @@ public class StdErrAppender implements JettyAppender /** * The stream to write logging events to. */ - private PrintStream stderr; + private PrintStream stream; public StdErrAppender(JettyLoggerConfiguration config) { - this(config, System.err); + this(config, null); } public StdErrAppender(JettyLoggerConfiguration config, PrintStream stream) @@ -72,7 +72,7 @@ public StdErrAppender(JettyLoggerConfiguration config, PrintStream stream) public StdErrAppender(JettyLoggerConfiguration config, PrintStream stream, TimeZone timeZone) { Objects.requireNonNull(config, "JettyLoggerConfiguration"); - this.stderr = Objects.requireNonNull(stream, "PrintStream"); + this.stream = stream; TimeZone tzone = timeZone; if (tzone == null) @@ -96,7 +96,14 @@ public void emit(JettyLogger logger, Level level, long timestamp, String threadN { StringBuilder builder = new StringBuilder(64); format(builder, logger, level, timestamp, threadName, throwable, message, argumentArray); - stderr.println(builder); + if (stream != null) + { + stream.println(builder); + } + else + { + System.err.println(builder); + } } public boolean isCondensedNames() @@ -116,12 +123,12 @@ public int getThreadPadding() public PrintStream getStream() { - return stderr; + return stream; } public void setStream(PrintStream stream) { - this.stderr = stream; + this.stream = stream; } private void format(StringBuilder builder, JettyLogger logger, Level level, long timestamp, String threadName, Throwable throwable, String message, Object... argumentArray)