Added in API level 1

Handler

abstract class Handler
kotlin.Any
   ↳ java.util.logging.Handler

A Handler object takes log messages from a Logger and exports them. It might for example, write them to a console or write them to a file, or send them to a network logging service, or forward them to an OS log, or whatever.

A Handler can be disabled by doing a setLevel(Level.OFF) and can be re-enabled by doing a setLevel with an appropriate level.

Handler classes typically use LogManager properties to set default values for the Handler's Filter, Formatter, and Level. See the specific documentation for each concrete Handler class.

Summary

Protected constructors

Default constructor.

Public methods
abstract Unit

Close the Handler and free all associated resources.

abstract Unit

Flush any buffered output.

open String!

Return the character encoding for this Handler.

open ErrorManager!

Retrieves the ErrorManager for this Handler.

open Filter!

Get the current Filter for this Handler.

open Formatter!

Return the Formatter for this Handler.

open Level!

Get the log level specifying which messages will be logged by this Handler.

open Boolean

Check if this Handler would actually log a given LogRecord.

abstract Unit
publish(record: LogRecord!)

Publish a LogRecord.

open Unit
setEncoding(encoding: String!)

Set the character encoding used by this Handler.

open Unit

Define an ErrorManager for this Handler.

open Unit
setFilter(newFilter: Filter!)

Set a Filter to control output on this Handler.

open Unit
setFormatter(newFormatter: Formatter!)

Set a Formatter.

open Unit
setLevel(newLevel: Level!)

Set the log level specifying which message levels will be logged by this Handler.

Protected methods
open Unit
reportError(msg: String!, ex: Exception!, code: Int)

Protected convenience method to report an error to this Handler's ErrorManager.

Protected constructors

Handler

Added in API level 1
protected Handler()

Default constructor. The resulting Handler has a log level of Level.ALL, no Formatter, and no Filter. A default ErrorManager instance is installed as the ErrorManager.

Public methods

close

Added in API level 1
abstract fun close(): Unit

Close the Handler and free all associated resources.

The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.

Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

flush

Added in API level 1
abstract fun flush(): Unit

Flush any buffered output.

getEncoding

Added in API level 1
open fun getEncoding(): String!

Return the character encoding for this Handler.

Return
String! The encoding name. May be null, which indicates the default encoding should be used.

getErrorManager

Added in API level 1
open fun getErrorManager(): ErrorManager!

Retrieves the ErrorManager for this Handler.

Return
ErrorManager! the ErrorManager for this Handler
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

getFilter

Added in API level 1
open fun getFilter(): Filter!

Get the current Filter for this Handler.

Return
Filter! a Filter object (may be null)

getFormatter

Added in API level 1
open fun getFormatter(): Formatter!

Return the Formatter for this Handler.

Return
Formatter! the Formatter (may be null).

getLevel

Added in API level 1
open fun getLevel(): Level!

Get the log level specifying which messages will be logged by this Handler. Message levels lower than this level will be discarded.

Return
Level! the level of messages being logged.

isLoggable

Added in API level 1
open fun isLoggable(record: LogRecord!): Boolean

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 also may make other Handler specific checks that might prevent a handler from logging the LogRecord. It will return false if the LogRecord is null.

Parameters
record LogRecord!: a LogRecord
Return
Boolean true if the LogRecord would be logged.

publish

Added in API level 1
abstract fun publish(record: LogRecord!): Unit

Publish a LogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.

Parameters
record LogRecord!: description of the log event. A null record is silently ignored and is not published

setEncoding

Added in API level 1
open fun setEncoding(encoding: String!): Unit

Set the character encoding used by this Handler.

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

Parameters
encoding String!: The name of a supported character encoding. May be null, to indicate the default platform encoding.
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").
java.io.UnsupportedEncodingException if the named encoding is not supported.

setErrorManager

Added in API level 1
open fun setErrorManager(em: ErrorManager!): Unit

Define an ErrorManager for this Handler.

The ErrorManager's "error" method will be invoked if any errors occur while using this Handler.

Parameters
em ErrorManager!: the new ErrorManager
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

setFilter

Added in API level 1
open fun setFilter(newFilter: Filter!): Unit

Set a Filter to control output on this Handler.

For each call of publish the Handler will call this Filter (if it is non-null) to check if the LogRecord should be published or discarded.

Parameters
newFilter Filter!: a Filter object (may be null)
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

setFormatter

Added in API level 1
open fun setFormatter(newFormatter: Formatter!): Unit

Set a Formatter. This Formatter will be used to format LogRecords for this Handler.

Some Handlers may not use Formatters, in which case the Formatter will be remembered, but not used.

Parameters
newFormatter Formatter!: the Formatter to use (may not be null)
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

setLevel

Added in API level 1
open fun setLevel(newLevel: Level!): Unit

Set the log level specifying which message levels will be logged by this Handler. Message levels lower than this value will be discarded.

The intention is to allow developers to turn on voluminous logging, but to limit the messages that are sent to certain Handlers.

Parameters
newLevel Level!: the new value for the log level
Exceptions
java.lang.SecurityException if a security manager exists and if the caller does not have LoggingPermission("control").

Protected methods

reportError

Added in API level 1
protected open fun reportError(
    msg: String!,
    ex: Exception!,
    code: Int
): Unit

Protected convenience method to report an error to this Handler's ErrorManager. Note that this method retrieves and uses the ErrorManager without doing a security check. It can therefore be used in environments where the caller may be non-privileged.

Parameters
msg String!: a descriptive string (may be null)
ex Exception!: an exception (may be null)
code Int: an error code defined in ErrorManager