Package org.jboss.logmanager
Class ExtHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- org.jboss.logmanager.ExtHandler
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,FlushableCloseable
- Direct Known Subclasses:
AsyncHandler,DelayedHandler,NullHandler,QueueHandler,SocketHandler,SyslogHandler,WriterHandler
public abstract class ExtHandler extends Handler implements FlushableCloseable
An extended logger handler. Use this class as a base class for log handlers which requireExtLogRecordinstances.
-
-
Field Summary
Fields Modifier and Type Field Description protected Handler[]handlersThe sub-handlers for this handler.protected static org.jboss.logmanager.AtomicArray<ExtHandler,Handler>handlersUpdaterThe atomic updater for thehandlersfield.
-
Constructor Summary
Constructors Modifier Constructor Description protectedExtHandler()Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(Handler handler)Add a sub-handler to this handler.Handler[]clearHandlers()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.Handler[]getHandlers()Get a copy of the sub-handlers array.booleanisAutoFlush()Determine if this handler will auto-flush.booleanisCallerCalculationRequired()Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.booleanisCloseChildren()Indicates whether or not children handlers should be closed when this handler is closed.booleanisEnabled()Determine if the handler is enabled.voidpublish(LogRecord record)voidpublish(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.voidsetCloseChildren(boolean closeChildren)Sets whether or not children handlers should be closed when this handler is closed.voidsetEnabled(boolean enabled)Enables or disables the handler based on the value passed in.voidsetEncoding(String encoding)voidsetErrorManager(ErrorManager em)voidsetFilter(Filter newFilter)voidsetFormatter(Formatter newFormatter)Handler[]setHandlers(Handler[] newHandlers)A convenience method to atomically get and replace the sub-handler array.voidsetLevel(Level newLevel)-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable
-
-
-
-
Field Detail
-
handlers
protected volatile Handler[] 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
protected static final org.jboss.logmanager.AtomicArray<ExtHandler,Handler> handlersUpdater
The atomic updater for thehandlersfield.
-
-
Method Detail
-
publish
public void publish(ExtLogRecord record)
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
protected void publishToNestedHandlers(ExtLogRecord record)
Publish a log record to each nested handler.- Parameters:
record- the log record to publish
-
doPublish
protected void doPublish(ExtLogRecord record)
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
public void addHandler(Handler handler)
Add a sub-handler to this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to add
-
removeHandler
public void removeHandler(Handler handler) throws SecurityException
Remove a sub-handler from this handler. Some handler types do not utilize sub-handlers.- Parameters:
handler- the handler to remove- Throws:
SecurityException
-
getHandlers
public Handler[] 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
public Handler[] clearHandlers() throws SecurityException
A convenience method to atomically get and clear all sub-handlers.- Returns:
- the old sub-handler array
- Throws:
SecurityException
-
setHandlers
public Handler[] setHandlers(Handler[] newHandlers) throws SecurityException
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
-
isAutoFlush
public boolean isAutoFlush()
Determine if this handler will auto-flush.- Returns:
trueif auto-flush is enabled
-
setAutoFlush
public void setAutoFlush(boolean autoFlush) throws SecurityExceptionChange the autoflush setting for this handler.- Parameters:
autoFlush-trueto automatically flush after each write; false otherwise- Throws:
SecurityException
-
setEnabled
public final void setEnabled(boolean enabled) throws SecurityExceptionEnables or disables the handler based on the value passed in.- Parameters:
enabled-trueto enable the handler orfalseto disable the handler.- Throws:
SecurityException
-
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
-
flush
public void flush()
Flush all child handlers.
-
close
public void close() throws SecurityExceptionClose all child handlers.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classHandler- Throws:
SecurityException
-
setFormatter
public void setFormatter(Formatter newFormatter) throws SecurityException
- Overrides:
setFormatterin classHandler- Throws:
SecurityException
-
setFilter
public void setFilter(Filter newFilter) throws SecurityException
- Overrides:
setFilterin classHandler- Throws:
SecurityException
-
setEncoding
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException
- Overrides:
setEncodingin classHandler- Throws:
SecurityExceptionUnsupportedEncodingException
-
setErrorManager
public void setErrorManager(ErrorManager em)
- Overrides:
setErrorManagerin classHandler
-
setLevel
public void setLevel(Level newLevel) throws SecurityException
- Overrides:
setLevelin classHandler- Throws:
SecurityException
-
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:
LogRecord.getSourceClassName(),ExtLogRecord.getSourceFileName(),ExtLogRecord.getSourceLineNumber(),LogRecord.getSourceMethodName()
-
reportError
protected void reportError(String msg, Exception ex, int code)
- Overrides:
reportErrorin classHandler
-
-