Handler

public abstract class Handler extends Object
Known Direct Subclasses
Known Indirect Subclasses

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.

Protected Constructor Summary

Handler()
Default constructor.

Public Method Summary

abstract void
close()
Close the Handler and free all associated resources.
abstract void
flush()
Flush any buffered output.
String
getEncoding()
Return the character encoding for this Handler.
ErrorManager
getErrorManager()
Retrieves the ErrorManager for this Handler.
Filter
getFilter()
Get the current Filter for this Handler.
Formatter
getFormatter()
Return the Formatter for this Handler.
synchronized Level
getLevel()
Get the log level specifying which messages will be logged by this Handler.
boolean
isLoggable(LogRecord record)
Check if this Handler would actually log a given LogRecord.
abstract void
publish(LogRecord record)
Publish a LogRecord.
void
setEncoding(String encoding)
Set the character encoding used by this Handler.
void
setErrorManager(ErrorManager em)
Define an ErrorManager for this Handler.
void
setFilter(Filter newFilter)
Set a Filter to control output on this Handler.
void
setFormatter(Formatter newFormatter)
Set a Formatter.
synchronized void
setLevel(Level newLevel)
Set the log level specifying which message levels will be logged by this Handler.

Protected Method Summary

void
reportError(String msg, Exception ex, int code)
Protected convenience method to report an error to this Handler's ErrorManager.

Inherited Method Summary

Protected Constructors

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

public abstract void close ()

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.

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

public abstract void flush ()

Flush any buffered output.

public String getEncoding ()

Return the character encoding for this Handler.

Returns
  • The encoding name. May be null, which indicates the default encoding should be used.

public ErrorManager getErrorManager ()

Retrieves the ErrorManager for this Handler.

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

public Filter