Skip to content

Most visited

Recently visited

navigation
Added in API level 1

StreamHandler

public class StreamHandler
extends Handler

java.lang.Object
   ↳ java.util.logging.Handler
     ↳ java.util.logging.StreamHandler
Known Direct Subclasses


A StreamHandler object writes log messages to an output stream, that is, objects of the class OutputStream.

A StreamHandler object reads the following properties from the log manager to initialize itself. A default value will be used if a property is not found or has an invalid value.

This class is not thread-safe.

Summary

Public constructors

StreamHandler()

Constructs a StreamHandler object.

StreamHandler(OutputStream os, Formatter formatter)

Constructs a StreamHandler object with the supplied output stream and formatter.

Public methods

void close()

Closes this handler.

void flush()

Flushes any buffered output.

boolean isLoggable(LogRecord record)

Determines whether the supplied log record needs to be logged.

void publish(LogRecord record)

Accepts a logging request.

void setEncoding(String charsetName)

Sets the character encoding used by this handler.

Protected methods

void setOutputStream(OutputStream os)

Sets the output stream this handler writes to.

Inherited methods

From class java.util.logging.Handler
From class java.lang.Object

Public constructors

StreamHandler

Added in API level 1
StreamHandler ()

Constructs a StreamHandler object. The new stream handler does not have an associated output stream.

StreamHandler

Added in API level 1
StreamHandler (OutputStream os, 
                Formatter formatter)

Constructs a StreamHandler object with the supplied output stream and formatter.

Parameters
os OutputStream: the output stream this handler writes to.
formatter Formatter: the formatter this handler uses to format the output.
Throws
NullPointerException if os or formatter is null.

Public methods

close

Added in API level 1
void close ()

Closes this handler. The tail string of the formatter associated with this handler is written out. A flush operation and a subsequent close operation is then performed upon the output stream. Client applications should not use a handler after closing it.

flush

Added in API level 1
void flush ()

Flushes any buffered output.

isLoggable

Added in API level 1
boolean isLoggable (LogRecord record)

Determines whether the supplied log record needs to be logged. The logging levels are checked as well as the filter. The output stream of this handler is also checked. If it is null, this method returns false.

Notice : Case of no output stream will return false.

Parameters
record LogRecord: the log record to be checked.
Returns
boolean true if record needs to be logged, false otherwise.

publish

Added in API level 1
void publish (LogRecord record)

Accepts a logging request. The log record is formatted and written to the output stream if the following three conditions are met:

  • the supplied log record has at least the required logging level;
  • the supplied log record passes the filter associated with this handler, if any;
  • the output stream associated with this handler is not null.
If it is the first time a log record is written out, the head string of the formatter associated with this handler is written out first.

Parameters
record LogRecord: the log record to be logged.

setEncoding

Added in API level 1
void setEncoding (String charsetName)

Sets the character encoding used by this handler. A null value indicates that the default encoding should be used.

Parameters
charsetName String
Throws
UnsupportedEncodingException if charsetName is not supported.

Protected methods

setOutputStream

Added in API level 1
void setOutputStream (OutputStream os)

Sets the output stream this handler writes to. If there's an existing output stream, the tail string of the associated formatter will be written to it. Then it will be flushed, closed and replaced with os.

Parameters
os OutputStream: the new output stream.
Throws
NullPointerException if os is null.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.