Class Handler
- Direct Known Subclasses:
MemoryHandler,StreamHandler
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.
- Since:
- 1.4
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Close theHandlerand free all associated resources.abstract voidflush()Flush any buffered output.Return the character encoding for thisHandler.Retrieves the ErrorManager for this Handler.Get the currentFilterfor thisHandler.Return theFormatterfor thisHandler.getLevel()Get the log level specifying which messages will be logged by thisHandler.booleanisLoggable(LogRecord record) Check if thisHandlerwould actually log a givenLogRecord.abstract voidPublish aLogRecord.protected voidreportError(String msg, Exception ex, int code) Protected convenience method to report an error to this Handler's ErrorManager.voidsetEncoding(String encoding) Set the character encoding used by thisHandler.voidDefine an ErrorManager for this Handler.voidSet aFilterto control output on thisHandler.voidsetFormatter(Formatter newFormatter) Set aFormatter.voidSet the log level specifying which message levels will be logged by thisHandler.
-
Constructor Details
-
Handler
protected Handler()Default constructor. The resultingHandlerhas a log level ofLevel.ALL, noFormatter, and noFilter. A defaultErrorManagerinstance is installed as theErrorManager.
-
-
Method Details
-
publish
Publish aLogRecord.The logging request was made initially to a
Loggerobject, which initialized theLogRecordand forwarded it here.The
Handleris responsible for formatting the message, when and if necessary. The formatting should include localization.- Parameters:
record- description of the log event. A null record is silently ignored and is not published
-
flush
public abstract void flush()Flush any buffered output. -
close
public abstract void close()Close theHandlerand free all associated resources.The close method will perform a
flushand then close theHandler. After close has been called thisHandlershould no longer be used. Method calls may either be silently ignored or may throw runtime exceptions. -
setFormatter
Set aFormatter. ThisFormatterwill be used to formatLogRecordsfor thisHandler.Some
Handlersmay not useFormatters, in which case theFormatterwill be remembered, but not used.- Parameters:
newFormatter- theFormatterto use (may not be null)
-
getFormatter
Return theFormatterfor thisHandler.- Returns:
- the
Formatter(may be null).
-
setEncoding
Set the character encoding used by thisHandler.The encoding should be set before any
LogRecordsare written to theHandler.- Parameters:
encoding- The name of a supported character encoding. May be null, to indicate the default platform encoding.- Throws:
UnsupportedEncodingException- if the named encoding is not supported.
-
getEncoding
Return the character encoding for thisHandler.- Returns:
- The encoding name. May be null, which indicates the default encoding should be used.
-
setFilter
Set aFilterto control output on thisHandler.For each call of
publishtheHandlerwill call thisFilter(if it is non-null) to check if theLogRecordshould be published or discarded.- Parameters:
newFilter- aFilterobject (may be null)
-
getFilter
Get the currentFilterfor thisHandler.- Returns:
- a
Filterobject (may be null)
-
setErrorManager
Define an ErrorManager for this Handler.The ErrorManager's "error" method will be invoked if any errors occur while using this Handler.
- Parameters:
em- the new ErrorManager
-
getErrorManager
Retrieves the ErrorManager for this Handler.- Returns:
- the ErrorManager for this Handler
-
reportError
-
setLevel
Set the log level specifying which message levels will be logged by thisHandler. 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- the new value for the log level
-
getLevel
Get the log level specifying which messages will be logged by thisHandler. Message levels lower than this level will be discarded.- Returns:
- the level of messages being logged.
-
isLoggable
Check if thisHandlerwould actually log a givenLogRecord.This method checks if the
LogRecordhas an appropriateLeveland whether it satisfies anyFilter. It also may make otherHandlerspecific checks that might prevent a handler from logging theLogRecord. It will return false if theLogRecordis null.- Parameters:
record- aLogRecord(may be null).- Returns:
- true if the
LogRecordwould be logged.
-