Package java.util.logging
Class Handler
java.lang.Object
java.util.logging.Handler
- Direct Known Subclasses:
MemoryHandler,StreamHandler
public abstract class Handler extends Object
A
Handler object accepts a logging request and exports the desired
messages to a target, for example, a file, the console, etc. It can be
disabled by setting its logging level to Level.OFF.-
Constructor Summary
Constructors Modifier Constructor Description protectedHandler()Constructs aHandlerobject with a default error manager instanceErrorManager, the default encoding, and the default logging levelLevel.ALL. -
Method Summary
Modifier and Type Method Description abstract voidclose()Closes this handler.abstract voidflush()Flushes any buffered output.StringgetEncoding()Gets the character encoding used by this handler,nullfor default encoding.ErrorManagergetErrorManager()Gets the error manager used by this handler to report errors during logging.FiltergetFilter()Gets the filter used by this handler.FormattergetFormatter()Gets the formatter used by this handler to format the logging messages.LevelgetLevel()Gets the logging level of this handler, records with levels lower than this value will be dropped.booleanisLoggable(LogRecord record)Determines whether the supplied log record needs to be logged.abstract voidpublish(LogRecord record)Accepts a logging request and sends it to the the target.protected voidreportError(String msg, Exception ex, int code)Reports an error to the error manager associated with this handler,ErrorManageris used for that purpose.voidsetEncoding(String charsetName)Sets the character encoding used by this handler,nullindicates a default encoding.voidsetErrorManager(ErrorManager newErrorManager)Sets the error manager for this handler.voidsetFilter(Filter newFilter)Sets the filter to be used by this handler.voidsetFormatter(Formatter newFormatter)Sets the formatter to be used by this handler.voidsetLevel(Level newLevel)Sets the logging level of the messages logged by this handler, levels lower than this value will be dropped.
-
Constructor Details
-
Handler
protected Handler()Constructs aHandlerobject with a default error manager instanceErrorManager, the default encoding, and the default logging levelLevel.ALL. It has no filter and no formatter.
-
-
Method Details
-
close
public abstract void close()Closes this handler. A flush operation will be performed and all the associated resources will be freed. Client applications should not use this handler after closing it. -
flush
public abstract void flush()Flushes any buffered output. -
publish
Accepts a logging request and sends it to the the target.- Parameters:
record- the log record to be logged;nullrecords are ignored.
-
getEncoding
Gets the character encoding used by this handler,nullfor default encoding.- Returns:
- the character encoding used by this handler.
-
getErrorManager
Gets the error manager used by this handler to report errors during logging.- Returns:
- the error manager used by this handler.
-
getFilter
Gets the filter used by this handler.- Returns:
- the filter used by this handler (possibly
null).
-
getFormatter
Gets the formatter used by this handler to format the logging messages.- Returns:
- the formatter used by this handler (possibly
null).
-
getLevel
Gets the logging level of this handler, records with levels lower than this value will be dropped.- Returns:
- the logging level of this handler.
-
isLoggable
Determines whether the supplied log record needs to be logged. The logging levels will be checked as well as the filter.- Parameters:
record- the log record to be checked.- Returns:
trueif the supplied log record needs to be logged, otherwisefalse.
-
reportError
Reports an error to the error manager associated with this handler,ErrorManageris used for that purpose. No security checks are done, therefore this is compatible with environments where the caller is non-privileged.- Parameters:
msg- the error message, may benull.ex- the associated exception, may benull.code- anErrorManagererror code.
-
setEncoding
Sets the character encoding used by this handler,nullindicates a default encoding.- Throws:
UnsupportedEncodingException- ifcharsetNameis not supported.
-
setErrorManager
Sets the error manager for this handler.- Parameters:
newErrorManager- the error manager to set.- Throws:
NullPointerException- ifemisnull.
-
setFilter
Sets the filter to be used by this handler.- Parameters:
newFilter- the filter to set, may benull.
-
setFormatter
Sets the formatter to be used by this handler.- Parameters:
newFormatter- the formatter to set.- Throws:
NullPointerException- ifnewFormatterisnull.
-
setLevel
Sets the logging level of the messages logged by this handler, levels lower than this value will be dropped.- Parameters:
newLevel- the logging level to set.- Throws:
NullPointerException- ifnewLevelisnull.
-