- java.lang.Object
- 
- java.util.logging.Handler
 
- 
- Direct Known Subclasses:
- MemoryHandler,- StreamHandler
 
 
 public abstract class Handler extends Object AHandlerobject takes log messages from aLoggerand 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 Handlercan be disabled by doing asetLevel(Level.OFF)and can be re-enabled by doing asetLevelwith an appropriate level.Handlerclasses typically useLogManagerproperties to set default values for theHandler'sFilter,Formatter, andLevel. See the specific documentation for each concreteHandlerclass.- Since:
- 1.4
 
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedHandler()Default constructor.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclose()Close theHandlerand free all associated resources.abstract voidflush()Flush any buffered output.StringgetEncoding()Return the character encoding for thisHandler.ErrorManagergetErrorManager()Retrieves the ErrorManager for this Handler.FiltergetFilter()Get the currentFilterfor thisHandler.FormattergetFormatter()Return theFormatterfor thisHandler.LevelgetLevel()Get the log level specifying which messages will be logged by thisHandler.booleanisLoggable(LogRecord record)Check if thisHandlerwould actually log a givenLogRecord.abstract voidpublish(LogRecord record)Publish 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.voidsetErrorManager(ErrorManager em)Define an ErrorManager for this Handler.voidsetFilter(Filter newFilter)Set aFilterto control output on thisHandler.voidsetFormatter(Formatter newFormatter)Set aFormatter.voidsetLevel(Level newLevel)Set the log level specifying which message levels will be logged by thisHandler.
 
- 
- 
- 
Method Detail- 
publishpublic abstract void publish(LogRecord record) 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
 
 - 
flushpublic abstract void flush() Flush any buffered output.
 - 
closepublic abstract void close() throws SecurityExceptionClose 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.- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
setFormatterpublic void setFormatter(Formatter newFormatter) throws SecurityException Set aFormatter. ThisFormatterwill be used to formatLogRecordsfor thisHandler.Some Handlersmay not useFormatters, in which case theFormatterwill be remembered, but not used.- Parameters:
- newFormatter- the- Formatterto use (may not be null)
- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
getFormatterpublic Formatter getFormatter() Return theFormatterfor thisHandler.- Returns:
- the Formatter(may be null).
 
 - 
setEncodingpublic void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException 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:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
- UnsupportedEncodingException- if the named encoding is not supported.
 
 - 
getEncodingpublic String getEncoding() Return the character encoding for thisHandler.- Returns:
- The encoding name. May be null, which indicates the default encoding should be used.
 
 - 
setFilterpublic void setFilter(Filter newFilter) throws SecurityException 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- a- Filterobject (may be null)
- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
getFilterpublic Filter getFilter() Get the currentFilterfor thisHandler.- Returns:
- a Filterobject (may be null)
 
 - 
setErrorManagerpublic void setErrorManager(ErrorManager em) 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
- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
getErrorManagerpublic ErrorManager getErrorManager() Retrieves the ErrorManager for this Handler.- Returns:
- the ErrorManager for this Handler
- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
reportErrorprotected void reportError(String msg, Exception ex, int code) 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- a descriptive string (may be null)
- ex- an exception (may be null)
- code- an error code defined in ErrorManager
 
 - 
setLevelpublic void setLevel(Level newLevel) throws SecurityException 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
- Throws:
- SecurityException- if a security manager exists and if the caller does not have- LoggingPermission("control").
 
 - 
getLevelpublic 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.
 
 - 
isLoggablepublic boolean isLoggable(LogRecord record) 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- a- LogRecord
- Returns:
- true if the LogRecordwould be logged.
 
 
- 
 
-