Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util.logging

Class StreamHandler

java.lang.Object
|
+--java.util.logging.Handler
   |
   +--java.util.logging.StreamHandler


public class StreamHandler

extends Handler

A StreamHandler publishes LogRecords to a instances of java.io.OutputStream.

Author:

Constructor Summary

StreamHandler()

Creates a StreamHandler without an output stream.
StreamHandler(java.io.OutputStream out, java.util.logging.Formatter formatter)

Creates a StreamHandler that formats log messages with the specified Formatter and publishes them to the specified output stream.

Method Summary

voidclose()

Closes this StreamHandler after having forced any data that may have been buffered to the underlying output device.
voidflush()

Forces any data that may have been buffered to the underlying output device.
booleanisLoggable(java.util.logging.LogRecord record)

Checks whether or not a LogRecord would be logged if it was passed to this StreamHandler for publication.
voidpublish(java.util.logging.LogRecord record)

Publishes a LogRecord to the associated output stream, provided the record passes all tests for being loggable.
voidsetEncoding(java.lang.String encoding)

Sets the character encoding which this handler uses for publishing log records.
voidsetOutputStream(java.io.OutputStream out)

Changes the output stream to which this handler publishes logging records.

Constructor Details

StreamHandler

public StreamHandler()

Creates a StreamHandler without an output stream. Subclasses can later use #setOutputStream(java.io.OutputStream) to associate an output stream with this StreamHandler.


StreamHandler

public StreamHandler(java.io.OutputStream out, java.util.logging.Formatter formatter)

Creates a StreamHandler that formats log messages with the specified Formatter and publishes them to the specified output stream.

Parameters:


Method Details

close

public void close()

Closes this StreamHandler after having forced any data that may have been buffered to the underlying output device.

As soon as close has been called, a Handler should not be used anymore. Attempts to publish log records, to flush buffers, or to modify the Handler in any other way may throw runtime exceptions after calling close.

In case of an I/O failure, the ErrorManager of this Handler will be informed, but the caller of this method will not receive an exception.

If a StreamHandler that has been closed earlier is closed a second time, the Sun J2SE 1.4 reference can be observed to silently ignore the call. The GNU implementation, however, intentionally behaves differently by informing the ErrorManager associated with this StreamHandler. Since the condition indicates a programming error, the programmer should be informed. It also seems extremely unlikely that any application would depend on the exact behavior in this rather obscure, erroneous case -- especially since the API specification does not prescribe what is supposed to happen.

Throws:


flush

public void flush()

Forces any data that may have been buffered to the underlying output device.

In case of an I/O failure, the ErrorManager of this Handler will be informed, but the caller of this method will not receive an exception.

If a StreamHandler that has been closed earlier is closed a second time, the Sun J2SE 1.4 reference can be observed to silently ignore the call. The GNU implementation, however, intentionally behaves differently by informing the ErrorManager associated with this StreamHandler. Since the condition indicates a programming error, the programmer should be informed. It also seems extremely unlikely that any application would depend on the exact behavior in this rather obscure, erroneous case -- especially since the API specification does not prescribe what is supposed to happen.


isLoggable

public boolean isLoggable(java.util.logging.LogRecord record)

Checks whether or not a LogRecord would be logged if it was passed to this StreamHandler for publication.

The StreamHandler implementation first checks whether a writer is present and the handler's level is greater than or equal to the severity level threshold. In a second step, if a Filter has been installed, its Filter#isLoggable(LogRecord) isLoggable method is invoked. Subclasses of StreamHandler can override this method to impose their own constraints.

Parameters:

Returns:

Throws:

See Also:


publish

public void publish(java.util.logging.LogRecord record)

Publishes a LogRecord to the associated output stream, provided the record passes all tests for being loggable. The StreamHandler will localize the message of the log record and substitute any message parameters.

Most applications do not need to call this method directly. Instead, they will use use a Logger, which will create LogRecords and distribute them to registered handlers.

In case of an I/O failure, the ErrorManager of this Handler will be informed, but the caller of this method will not receive an exception.

If a log record is being published to a StreamHandler that has been closed earlier, the Sun J2SE 1.4 reference can be observed to silently ignore the call. The GNU implementation, however, intentionally behaves differently by informing the ErrorManager associated with this StreamHandler. Since the condition indicates a programming error, the programmer should be informed. It also seems extremely unlikely that any application would depend on the exact behavior in this rather obscure, erroneous case -- especially since the API specification does not prescribe what is supposed to happen.

Parameters:


setEncoding

public void setEncoding(java.lang.String encoding)

Sets the character encoding which this handler uses for publishing log records. The encoding of a StreamHandler must be set before any log records have been published.

Parameters:

Throws:


setOutputStream

protected void setOutputStream(java.io.OutputStream out)

Changes the output stream to which this handler publishes logging records.

Parameters:

Throws: