Android
java.util.logging
public class

java.util.logging.StreamHandler

java.lang.Object
java.util.logging.Handler
java.util.logging.StreamHandler

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

A StreamHandler object reads the following properties from the log manager to initialize itself:

  • java.util.logging.StreamHandler.level specifies the logging level, defaults to Level.INFO if this property is not found or has an invalid value;
  • java.util.logging.StreamHandler.filter specifies the name of the filter class to be associated with this handler, defaults to null if this property is not found or has an invalid value;
  • java.util.logging.StreamHandler.formatter specifies the name of the formatter class to be associated with this handler, defaults to java.util.logging.SimpleFormatter if this property is not found or has an invalid value;
  • java.util.logging.StreamHandler.encoding specifies the encoding this handler will use to encode log messages, defaults to null if this property is not found or has an invalid value.

This class is not thread-safe.

Known Direct Subclasses

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 need to be logged.
  synchronized        void  publish(LogRecord record)
Accepts an actual logging request.
          void  setEncoding(String encoding)
Sets the character encoding used by this handler.

Protected Methods

          void  setOutputStream(OutputStream os)
Sets the output stream this handler writes to.
Methods inherited from class java.util.logging.Handler
Methods inherited from class java.lang.Object

Details

Public Constructors

public StreamHandler()

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

public StreamHandler(OutputStream os, Formatter formatter)

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

Parameters

os the output stream this handler writes to
formatter the formatter this handler uses to format the output

Public Methods

public void close()

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

Throws

SecurityException If a security manager determines that the caller does not have the required permission.

public void flush()

Flushes any buffered output.

public boolean isLoggable(LogRecord record)

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

Parameters

record the log record to be checked

Returns

  • true if the supplied log record need to be logged, otherwise false

public synchronized void publish(LogRecord record)

Accepts an actual logging request. The log record will be 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 need to be written out, the head string of the formatter associated with this handler will be written out first.

Parameters

record the log record to be logged

public void setEncoding(String encoding)

Sets the character encoding used by this handler. A null value indicates the using of the default encoding.

Parameters

encoding the character encoding to set

Throws

SecurityException If a security manager determines that the caller does not have the required permission.
UnsupportedEncodingException If the specified encoding is not supported by the runtime.

Protected Methods

protected 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 and closed.

Parameters

os the new output stream

Throws

SecurityException If a security manager determines that the caller does not have the required permission.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56