org.apache.tomcat.util.log

## Class SystemLogHandler

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - java.io.PrintStream
      - - org.apache.tomcat.util.log.SystemLogHandler

All Implemented Interfaces:
  Closeable, Flushable, Appendable, AutoCloseable

    public class SystemLogHandler
    extends PrintStream

This helper class may be used to do sophisticated redirection of System.out and System.err on a per Thread basis. A stack is implemented per Thread so that nested startCapture and stopCapture can be used.

Author:
  Remy Maucherat, Glenn L. Nielsen

### Field Summary

Fields
`protected static ThreadLocal<Stack<org.apache.tomcat.util.log.CaptureLog>>` `logs` Thread <-> CaptureLog associations.
`protected PrintStream` `out` Wrapped PrintStream.
`protected static Stack<org.apache.tomcat.util.log.CaptureLog>` `reuse` Spare CaptureLog ready for reuse.

### Constructor Summary

Constructors
Constructor and Description
`SystemLogHandler(PrintStream wrapped)` Construct the handler to capture the output of the given steam.

### Method Summary

Methods
`boolean` `checkError()`
`void` `close()`
`protected PrintStream` `findStream()` Find PrintStream to which the output must be written to.
`void` `flush()`
`void` `print(boolean b)`
`void` `print(char c)`
`void` `print(char[] s)`
`void` `print(double d)`
`void` `print(float f)`
`void` `print(int i)`
`void` `print(long l)`
`void` `print(Object obj)`
`void` `print(String s)`
`void` `println()`
`void` `println(boolean x)`
`void` `println(char x)`
`void` `println(char[] x)`
`void` `println(double x)`
`void` `println(float x)`
`void` `println(int x)`
`void` `println(long x)`
`void` `println(Object x)`
`void` `println(String x)`
`protected void` `setError()`
`static void` `startCapture()` Start capturing thread's output.
`static String` `stopCapture()` Stop capturing thread's output and return captured data as a String.
`void` `write(byte[] b)`
`void` `write(byte[] buf, int off, int len)`
`void` `write(int b)`

### Methods inherited from class java.io.PrintStream

`append, append, append, clearError, format, format, printf, printf`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### out

    protected PrintStream out

Wrapped PrintStream.

#### logs

    protected static ThreadLocal<Stack<org.apache.tomcat.util.log.CaptureLog>> logs

Thread <-> CaptureLog associations.

#### reuse

    protected static Stack<org.apache.tomcat.util.log.CaptureLog> reuse

Spare CaptureLog ready for reuse.

### Constructor Detail

#### SystemLogHandler

    public SystemLogHandler(PrintStream wrapped)

Construct the handler to capture the output of the given steam.

### Method Detail

#### startCapture

    public static void startCapture()

Start capturing thread's output.

#### stopCapture

    public static String stopCapture()

Stop capturing thread's output and return captured data as a String.

#### findStream

    protected PrintStream findStream()

Find PrintStream to which the output must be written to.

#### flush

    public void flush()

Specified by:
  `flush` in interface `Flushable`
Overrides:
  `flush` in class `PrintStream`

#### close

    public void close()

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Overrides:
  `close` in class `PrintStream`

#### checkError

    public boolean checkError()

Overrides:
  `checkError` in class `PrintStream`

#### setError

    protected void setError()

Overrides:
  `setError` in class `PrintStream`

#### write

    public void write(int b)

Overrides:
  `write` in class `PrintStream`

#### write

    public void write(byte[] b)
               throws IOException

Overrides:
  `write` in class `FilterOutputStream`
Throws:
  `IOException`

#### write

    public void write(byte[] buf,
             int off,
             int len)

Overrides:
  `write` in class `PrintStream`

#### print

    public void print(boolean b)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(char c)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(int i)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(long l)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(float f)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(double d)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(char[] s)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(String s)

Overrides:
  `print` in class `PrintStream`

#### print

    public void print(Object obj)

Overrides:
  `print` in class `PrintStream`

#### println

    public void println()

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(boolean x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(char x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(int x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(long x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(float x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(double x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(char[] x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(String x)

Overrides:
  `println` in class `PrintStream`

#### println

    public void println(Object x)

Overrides:
  `println` in class `PrintStream`