# StreamHandler

public class **StreamHandler** extends [Handler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html)  

|---|---|---|
| Known Direct Subclasses [ConsoleHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/ConsoleHandler.html), [FileHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/FileHandler.html) |---|---| | [ConsoleHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/ConsoleHandler.html) | This Handler publishes log records to System.err. | | [FileHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/FileHandler.html) | Simple file logging Handler. | |||

Stream based logging Handler.


This is primarily intended as a base class or support class to
be used in implementing other logging Handlers.


LogRecords are published to a given java.io.OutputStream.


**Configuration:**
By default each StreamHandler is initialized using the following
LogManager configuration properties where \<handler-name\>
refers to the fully-qualified class name of the handler.
If properties are not defined
(or have invalid values) then the specified default values are used.

- \<handler-name\>.level specifies the default level for the Handler (defaults to Level.INFO).
- \<handler-name\>.filter specifies the name of a Filter class to use (defaults to no Filter).
- \<handler-name\>.formatter specifies the name of a Formatter class to use (defaults to java.util.logging.SimpleFormatter).
- \<handler-name\>.encoding the name of the character set encoding to use (defaults to the default platform encoding).


For example, the properties for `StreamHandler` would be:

- java.util.logging.StreamHandler.level=INFO
- java.util.logging.StreamHandler.formatter=java.util.logging.SimpleFormatter


For a custom handler, e.g. com.foo.MyHandler, the properties would be:

- com.foo.MyHandler.level=INFO
- com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter

<br />

### Public Constructor Summary

|---|---|
|   | [StreamHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#StreamHandler())() Create a StreamHandler, with no current output stream. |
|   | [StreamHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#StreamHandler(java.io.OutputStream,%20java.util.logging.Formatter))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Formatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Formatter.html) formatter) Create a StreamHandler with a given Formatter and output stream. |

### Public Method Summary

|---|---|
| synchronized void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#close())() Close the current output stream. |
| synchronized void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#flush())() Flush any buffered messages. |
| boolean | [isLoggable](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#isLoggable(java.util.logging.LogRecord))([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record) Check if this Handler would actually log a given LogRecord. |
| synchronized void | [publish](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#publish(java.util.logging.LogRecord))([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record) Format and publish a LogRecord. |
| synchronized void | [setEncoding](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#setEncoding(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) encoding) Set (or change) the character encoding used by this Handler. |

### Protected Method Summary

|---|---|
| synchronized void | [setOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/StreamHandler.html#setOutputStream(java.io.OutputStream))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out) Change the output stream. |

### Inherited Method Summary

From class [java.util.logging.Handler](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#close())() Close the Handler and free all associated resources. |
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#flush())() Flush any buffered output. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getEncoding](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#getEncoding())() Return the character encoding for this Handler. |
| [ErrorManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/ErrorManager.html) | [getErrorManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#getErrorManager())() Retrieves the ErrorManager for this Handler. |
| [Filter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Filter.html) | [getFilter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#getFilter())() Get the current Filter for this Handler. |
| [Formatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Formatter.html) | [getFormatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#getFormatter())() Return the Formatter for this Handler. |
| [Level](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Level.html) | [getLevel](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#getLevel())() Get the log level specifying which messages will be logged by this Handler. |
| boolean | [isLoggable](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#isLoggable(java.util.logging.LogRecord))([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record) Check if this Handler would actually log a given LogRecord. |
| abstract void | [publish](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#publish(java.util.logging.LogRecord))([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record) Publish a LogRecord. |
| void | [reportError](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#reportError(java.lang.String,%20java.lang.Exception,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) msg, [Exception](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Exception.html) ex, int code) Protected convenience method to report an error to this Handler's ErrorManager. |
| synchronized void | [setEncoding](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#setEncoding(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) encoding) Set the character encoding used by this Handler. |
| synchronized void | [setErrorManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#setErrorManager(java.util.logging.ErrorManager))([ErrorManager](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/ErrorManager.html) em) Define an ErrorManager for this Handler. |
| synchronized void | [setFilter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#setFilter(java.util.logging.Filter))([Filter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Filter.html) newFilter) Set a Filter to control output on this Handler. |
| synchronized void | [setFormatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#setFormatter(java.util.logging.Formatter))([Formatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Formatter.html) newFormatter) Set a Formatter. |
| synchronized void | [setLevel](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Handler.html#setLevel(java.util.logging.Level))([Level](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Level.html) newLevel) Set the log level specifying which message levels will be logged by this Handler. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**StreamHandler**
()

Create a StreamHandler, with no current output stream.

#### public
**StreamHandler**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Formatter](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Formatter.html) formatter)

Create a StreamHandler with a given Formatter
and output stream.

<br />

##### Parameters

| out | the target output stream |
| formatter | Formatter to be used to format output |
|---|---|

## Public Methods

#### public synchronized void
**close**
()

Close the current output stream.


The Formatter's "tail" string is written to the stream before it
is closed. In addition, if the Formatter's "head" string has not
yet been written to the stream, it will be written before the
"tail" string.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and if the caller does not have LoggingPermission("control"). |
|---|---|

#### public synchronized void
**flush**
()

Flush any buffered messages.

#### public boolean
**isLoggable**
([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record)

Check if this Handler would actually log a given LogRecord.


This method checks if the LogRecord has an appropriate level and
whether it satisfies any Filter. It will also return false if
no output stream has been assigned yet or the LogRecord is null.

<br />

##### Parameters

| record | a LogRecord |
|---|---|

##### Returns

- true if the LogRecord would be logged.

#### public synchronized void
**publish**
([LogRecord](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/LogRecord.html) record)

Format and publish a LogRecord.


The StreamHandler first checks if there is an OutputStream
and if the given LogRecord has at least the required log level.
If not it silently returns. If so, it calls any associated
Filter to check if the record should be published. If so,
it calls its Formatter to format the record and then writes
the result to the current output stream.


If this is the first LogRecord to be written to a given
OutputStream, the Formatter's "head" string is
written to the stream before the LogRecord is written.

##### Parameters

| record | description of the log event. A null record is silently ignored and is not published |
|---|---|

#### public synchronized void
**setEncoding**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) encoding)

Set (or change) the character encoding used by this Handler.


The encoding should be set before any LogRecords are written
to the Handler.

##### Parameters

| encoding | The name of a supported character encoding. May be null, to indicate the default platform encoding. |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and if the caller does not have LoggingPermission("control"). |
| [UnsupportedEncodingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/UnsupportedEncodingException.html) | if the named encoding is not supported. |
|---|---|

## Protected Methods

#### protected synchronized void
**setOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out)

Change the output stream.


If there is a current output stream then the Formatter's
tail string is written and the stream is flushed and closed.
Then the output stream is replaced with the new output stream.

##### Parameters

| out | New output stream. May not be null. |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and if the caller does not have LoggingPermission("control"). |
|---|---|