Package org.jboss.logmanager
Class ExtHandler
java.lang.Object
java.util.logging.Handler
org.jboss.logmanager.ExtHandler
- All Implemented Interfaces:
Flushable,AutoCloseable
- Direct Known Subclasses:
AsyncHandler,DelayedHandler,QueueHandler,SocketHandler,SyslogHandler,WriterHandler
An extended logger handler. Use this class as a base class for log handlers which require
ExtLogRecord
instances.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Handler[]The sub-handlers for this handler.protected static final org.jboss.logmanager.AtomicArray<ExtHandler, Handler> The atomic updater for thehandlersfield.protected final ReentrantLock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandler(Handler handler) Add a sub-handler to this handler.protected static voidCheck access.protected static voidcheckAccess(ExtHandler handler) Deprecated.Handler[]A convenience method to atomically get and clear all sub-handlers.voidclose()Close all child handlers.protected voiddoPublish(ExtLogRecord record) Do the actual work of publication; the record will have been filtered already.voidflush()Flush all child handlers.Get the handler's character set.Get the name of the handler's character set.Handler[]Get a copy of the sub-handlers array.getLevel()booleanDetermine if this handler will auto-flush.booleanIndicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.booleanIndicates whether or not children handlers should be closed when this handler is closed.final booleanDetermine if the handler is enabled.voidvoidpublish(ExtLogRecord record) Publish anExtLogRecord.protected voidpublishToNestedHandlers(ExtLogRecord record) Publish a log record to each nested handler.voidremoveHandler(Handler handler) Remove a sub-handler from this handler.protected voidreportError(String msg, Exception ex, int code) static voidreportError(Handler handler, String msg, Exception ex, int code) Report an error using a handler's specific error manager, if any.voidsetAutoFlush(boolean autoFlush) Change the autoflush setting for this handler.voidsetCharset(Charset charset) Set the handler's character set.protected voidsetCharsetPrivate(Charset charset) Set the handler's character set from within this handler.voidsetCloseChildren(boolean closeChildren) Sets whether or not children handlers should be closed when this handler is closed.final voidsetEnabled(boolean enabled) Enables or disables the handler based on the value passed in.voidsetEncoding(String encoding) Set the handler's character set by name.voidvoidvoidsetFormatter(Formatter newFormatter) Handler[]setHandlers(Handler[] newHandlers) A convenience method to atomically get and replace the sub-handler array.voidMethods inherited from class java.util.logging.Handler
isLoggable
-
Field Details
-
lock
-
handlers
The sub-handlers for this handler. May only be updated using thehandlersUpdateratomic updater. The array instance should not be modified (treat as immutable). -
handlersUpdater
The atomic updater for thehandlersfield.
-
-
Constructor Details
-
ExtHandler
protected ExtHandler()Construct a new instance.
-
-
Method Details
-
publish
-
publish
Publish anExtLogRecord. The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here. TheExtHandleris responsible for formatting the message, when and if necessary. The formatting should include localization.- Parameters:
record- the log record to publish
-
publishToNestedHandlers
Publish a log record to each nested handler.- Parameters:
record- the log record to publish
-
doPublish
Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if theautoFlushproperty is set totrue; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.- Parameters:
record- the log record to publish
-
addHandler
Add a sub-handler to this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to add- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
removeHandler
Remove a sub-handler from this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to remove- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
getHandlers
Get a copy of the sub-handlers array. Since the returned value is a copy, it may be freely modified.- Returns:
- a copy of the sub-handlers array
-
clearHandlers
A convenience method to atomically get and clear all sub-handlers.- Returns:
- the old sub-handler array
- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
setHandlers
A convenience method to atomically get and replace the sub-handler array.- Parameters:
newHandlers- the new sub-handlers- Returns:
- the old sub-handler array
- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
isAutoFlush
public boolean isAutoFlush()Determine if this handler will auto-flush.- Returns:
trueif auto-flush is enabled
-
setAutoFlush
Change the autoflush setting for this handler.- Parameters:
autoFlush-trueto automatically flush after each write;falseotherwise- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
setEnabled
Enables or disables the handler based on the value passed in.- Parameters:
enabled-trueto enable the handler orfalseto disable the handler.- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
isEnabled
public final boolean isEnabled()Determine if the handler is enabled.- Returns:
trueif the handler is enabled, otherwisefalse.
-
isCloseChildren
public boolean isCloseChildren()Indicates whether or not children handlers should be closed when this handler is closed.- Returns:
trueif the children handlers should be closed when this handler is closed,falseif children handlers should not be closed when this handler is closed
-
setCloseChildren
public void setCloseChildren(boolean closeChildren) Sets whether or not children handlers should be closed when this handler is closed.- Parameters:
closeChildren-trueif all children handlers should be closed when this handler is closed,falseif children handlers will not be closed when this handler is closed
-
checkAccess
Check access.- Throws:
SecurityException- if a security manager is installed and the caller does not have the"control" LoggingPermission
-
checkAccess
Deprecated.Check access.- Parameters:
handler- the handler to check access on.- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
flush
public void flush()Flush all child handlers. -
close
Close all child handlers.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classHandler- Throws:
SecurityException
-
setFormatter
- Overrides:
setFormatterin classHandler- Throws:
SecurityException
-
getFormatter
- Overrides:
getFormatterin classHandler
-
setFilter
- Overrides:
setFilterin classHandler- Throws:
SecurityException
-
getFilter
-
setEncoding
Set the handler's character set by name. This is roughly equivalent to callingsetCharset(Charset)with the results ofCharset.forName(String).- Overrides:
setEncodingin classHandler- Parameters:
encoding- the name of the encoding- Throws:
SecurityException- if a security manager is installed and the caller does not have the"control" LoggingPermissionUnsupportedEncodingException- if no character set could be found for the encoding name
-
getEncoding
Get the name of the handler's character set.- Overrides:
getEncodingin classHandler- Returns:
- the handler character set name
-
setCharset
Set the handler's character set. If not set, the handler's character set is initialized to the platform default character set.- Parameters:
charset- the character set (must not benull)- Throws:
SecurityException- if a security manager is installed and the caller does not have the"control" LoggingPermission
-
setCharsetPrivate
Set the handler's character set from within this handler. If not set, the handler's character set is initialized to the platform default character set.- Parameters:
charset- the character set (must not benull)- Throws:
SecurityException
-
getCharset
Get the handler's character set.- Returns:
- the character set in use (not
null)
-
setErrorManager
- Overrides:
setErrorManagerin classHandler
-
getErrorManager
- Overrides:
getErrorManagerin classHandler
-
setLevel
- Overrides:
setLevelin classHandler- Throws:
SecurityException
-
getLevel
-
isCallerCalculationRequired
public boolean isCallerCalculationRequired()Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.Calculating the caller on a log record can be an expensive operation. Some handlers may be required to copy some data from the log record, but may not need the caller information. If the formatter is a
ExtFormattertheExtFormatter.isCallerCalculationRequired()is used to determine if calculation of the caller is required.- Returns:
trueif the caller should be calculated, otherwisefalseif it can be skipped- See Also:
-
reportError
- Overrides:
reportErrorin classHandler
-
reportError
Report an error using a handler's specific error manager, if any.- Parameters:
handler- the handlermsg- the error messageex- the exceptioncode- the error code
-