Skip to content

Commit

Permalink
Merge pull request #4689 from eclipse/jetty-10.0.x-4620-stderr-consol…
Browse files Browse the repository at this point in the history
…e-capture

Issue #4620 - support alt PrintStream in StdErrAppender properly
  • Loading branch information
joakime authored Mar 23, 2020
2 parents ea1418a + fc722bf commit dfc2568
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit dfc2568

Please sign in to comment.