Top Description Fields Constructors Methods
org.apache.tomcat.util.log

public Class SystemLogHandler

extends PrintStream
Class Inheritance
Imports
java.io.IOException, .PrintStream, java.util.ArrayDeque, .Deque, .NoSuchElementException, .Queue, java.util.concurrent.ConcurrentLinkedQueue

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.
Authors
Remy Maucherat, Glenn L. Nielsen

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<Deque<CaptureLog>>
logs

Thread <-> CaptureLog associations.

private final PrintStream
out

Hides java.io.FilterOutputStream.out.

Wrapped PrintStream.
private static final Queue<CaptureLog>
reuse

Spare CaptureLog ready for reuse.

Constructor Summary

AccessConstructor and Description
public
SystemLogHandler(PrintStream
The stream to capture
wrapped
)

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

Method Summary

Modifier and TypeMethod and Description
public boolean
checkError()

Overrides java.io.PrintStream.checkError.

Flushes the stream if it's not closed and checks its error state.

public void
close()

Overrides java.io.PrintStream.close.

Implements java.io.Closeable.close.

Closes the stream.

protected PrintStream

Returns:

the print stream
findStream
()

Find PrintStream to which the output must be written to.

public void
flush()

Overrides java.io.PrintStream.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

public void
println()

Overrides java.io.PrintStream.println.

Terminates the current line by writing the line separator string.

public void
println(boolean
The boolean to be printed
x
)

Overrides java.io.PrintStream.println.

Prints a boolean and then terminates the line.

public void
println(char
The char to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints a character and then terminates the line.

public void
println(int
The int to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints an integer and then terminates the line.

public void
println(long
a The long to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints a long and then terminates the line.

public void
println(float
The float to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints a float and then terminates the line.

public void
println(double
The double to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints a double and then terminates the line.

public void
println(char[]
an array of chars to print.
x
)

Overrides java.io.PrintStream.println.

Prints an array of characters and then terminates the line.

public void
println(String
The String to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints a String and then terminates the line.

public void
println(Object
The Object to be printed.
x
)

Overrides java.io.PrintStream.println.

Prints an Object and then terminates the line.

protected void
setError()

Overrides java.io.PrintStream.setError.

Sets the error state of the stream to true.

public static void
startCapture()

Start capturing thread's output.

public static String

Returns:

The captured data
stopCapture
()

Stop capturing thread's output.

public void
write(int
The byte to be written
b
)

Overrides java.io.PrintStream.write.

Writes the specified byte to this stream.

public void
write(byte[]
A byte array
b
)

Overrides java.io.PrintStream.write.

Writes all bytes from the specified byte array to this stream.

public void
write(byte[]
A byte array
buf
,
int
Offset from which to start taking bytes
off
,
int
Number of bytes to write
len
)

Overrides java.io.PrintStream.write.

Writes len bytes from the specified byte array starting at offset off to this stream.

Inherited from java.io.PrintStream:
appendappendappendcharsetclearErrorformatformatprintfprintfwriteBytes

Field Detail

logsback to summary
private static final ThreadLocal<Deque<CaptureLog>> logs

Thread <-> CaptureLog associations.

outback to summary
private final PrintStream out

Hides java.io.FilterOutputStream.out.

Wrapped PrintStream.

reuseback to summary
private static final Queue<CaptureLog> reuse

Spare CaptureLog ready for reuse.

Constructor Detail

SystemLogHandlerback to summary
public SystemLogHandler(PrintStream wrapped)

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

Parameters
wrapped:PrintStream

The stream to capture

Method Detail

checkErrorback to summary
public boolean checkError()

Overrides java.io.PrintStream.checkError.

Doc from java.io.PrintStream.checkError.

Flushes the stream if it's not closed and checks its error state.

Returns:boolean

true if and only if this stream has encountered an IOException, or the setError method has been invoked

Annotations
@Override
closeback to summary
public void close()

Overrides java.io.PrintStream.close.

Implements java.io.Closeable.close.

Doc from java.io.PrintStream.close.

Closes the stream. This is done by flushing the stream and then closing the underlying output stream.

Annotations
@Override
findStreamback to summary
protected PrintStream findStream()

Find PrintStream to which the output must be written to.

Returns:PrintStream

the print stream

flushback to summary
public void flush()

Overrides java.io.PrintStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.PrintStream.flush.

Flushes the stream. This is done by writing any buffered output bytes to the underlying output stream and then flushing that stream.

Annotations
@Override
printlnback to summary
public void println()

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

Annotations
@Override
printlnback to summary
public void println(boolean x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a boolean and then terminates the line. This method behaves as though it invokes print(boolean) and then println().

Parameters
x:boolean

The boolean to be printed

Annotations
@Override
printlnback to summary
public void println(char x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a character and then terminates the line. This method behaves as though it invokes print(char) and then println().

Parameters
x:char

The char to be printed.

Annotations
@Override
printlnback to summary
public void println(int x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints an integer and then terminates the line. This method behaves as though it invokes print(int) and then println().

Parameters
x:int

The int to be printed.

Annotations
@Override
printlnback to summary
public void println(long x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a long and then terminates the line. This method behaves as though it invokes print(long) and then println().

Parameters
x:long

a The long to be printed.

Annotations
@Override
printlnback to summary
public void println(float x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a float and then terminates the line. This method behaves as though it invokes print(float) and then println().

Parameters
x:float

The float to be printed.

Annotations
@Override
printlnback to summary
public void println(double x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a double and then terminates the line. This method behaves as though it invokes print(double) and then println().

Parameters
x:double

The double to be printed.

Annotations
@Override
printlnback to summary
public void println(char[] x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints an array of characters and then terminates the line. This method behaves as though it invokes print(char[]) and then println().

Parameters
x:char[]

an array of chars to print.

Annotations
@Override
printlnback to summary
public void println(String x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints a String and then terminates the line. This method behaves as though it invokes print(String) and then println().

Parameters
x:String

The String to be printed.

Annotations
@Override
printlnback to summary
public void println(Object x)

Overrides java.io.PrintStream.println.

Doc from java.io.PrintStream.println.

Prints an Object and then terminates the line. This method calls at first String.valueOf(x) to get the printed object's string value, then behaves as though it invokes print(String) and then println().

Parameters
x:Object

The Object to be printed.

Annotations
@Override
setErrorback to summary
protected void setError()

Overrides java.io.PrintStream.setError.

Doc from java.io.PrintStream.setError.

Sets the error state of the stream to true.

This method will cause subsequent invocations of checkError() to return true until clearError() is invoked.

Annotations
@Override
startCaptureback to summary
public static void startCapture()

Start capturing thread's output.

stopCaptureback to summary
public static String stopCapture()

Stop capturing thread's output.

Returns:String

The captured data

writeback to summary
public void write(int b)

Overrides java.io.PrintStream.write.

Doc from java.io.PrintStream.write.

Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the byte is written as given; to write a character that will be translated according to the default charset, use the print(char) or println(char) methods.

Parameters
b:int

The byte to be written

Annotations
@Override
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.PrintStream.write.

Doc from java.io.PrintStream.write.

Writes all bytes from the specified byte array to this stream. If automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the bytes will be written as given; to write characters that will be translated according to the default charset, use the print(char[]) or println(char[]) methods.

Parameters
b:byte[]

A byte array

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs.
writeback to summary
public void write(byte[] buf, int off, int len)

Overrides java.io.PrintStream.write.

Doc from java.io.PrintStream.write.

Writes len bytes from the specified byte array starting at offset off to this stream. If automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the bytes will be written as given; to write characters that will be translated according to the default charset, use the print(char) or println(char) methods.

Parameters
buf:byte[]

A byte array

off:int

Offset from which to start taking bytes

len:int

Number of bytes to write

Annotations
@Override