Package org.jboss.logmanager.handlers
Class QueueHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- org.jboss.logmanager.ExtHandler
-
- org.jboss.logmanager.handlers.QueueHandler
-
- All Implemented Interfaces:
Flushable,AutoCloseable
public class QueueHandler extends ExtHandler
A queue handler which retains the last few messages logged. The handler can be used as-is to remember recent messages, or one or more handlers may be nested, which allows this handler to "replay" messages to the child handler(s) upon request.- Author:
- David M. Lloyd
-
-
Field Summary
-
Fields inherited from class org.jboss.logmanager.ExtHandler
handlers, handlersUpdater, lock
-
-
Constructor Summary
Constructors Constructor Description QueueHandler()Construct a new instance with a default queue length.QueueHandler(int limit)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(Handler handler)Add a sub-handler to this handler.voidaddHandler(Handler handler, boolean replay)Add the given handler, optionally atomically replaying the queue, allowing the delegate handler to receive all queued messages as well as all subsequent messages with no loss or reorder in between.protected voiddoPublish(ExtLogRecord record)Do the actual work of publication; the record will have been filtered already.intgetLimit()Get the queue length limit.ExtLogRecord[]getQueue()Get a copy of the queue as it is at an exact moment in time.String[]getQueueAsStrings()Get a copy of the queue, rendering each record as a string.voidpublish(LogRecord record)voidpublish(ExtLogRecord record)Publish anExtLogRecord.voidreplay()Replay the stored queue to the nested handlers.voidsetLimit(int limit)Set the queue length limit.-
Methods inherited from class org.jboss.logmanager.ExtHandler
checkAccess, checkAccess, clearHandlers, close, flush, getCharset, getEncoding, getErrorManager, getFilter, getFormatter, getHandlers, getLevel, isAutoFlush, isCallerCalculationRequired, isCloseChildren, isEnabled, publishToNestedHandlers, removeHandler, reportError, reportError, setAutoFlush, setCharset, setCharsetPrivate, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setHandlers, setLevel
-
Methods inherited from class java.util.logging.Handler
isLoggable
-
-
-
-
Method Detail
-
publish
public void publish(ExtLogRecord record)
Description copied from class:ExtHandlerPublish 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.- Overrides:
publishin classExtHandler- Parameters:
record- the log record to publish
-
publish
public void publish(LogRecord record)
Description copied from class:ExtHandler- Overrides:
publishin classExtHandler
-
doPublish
protected void doPublish(ExtLogRecord record)
Description copied from class:ExtHandlerDo 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.- Overrides:
doPublishin classExtHandler- Parameters:
record- the log record to publish
-
getLimit
public int getLimit()
Get the queue length limit. This is the number of messages that will be saved before old messages roll off of the queue.- Returns:
- the queue length limit
-
setLimit
public void setLimit(int limit)
Set the queue length limit. This is the number of messages that will be saved before old messages roll off of the queue.- Parameters:
limit- the queue length limit
-
addHandler
public void addHandler(Handler handler) throws SecurityException
Description copied from class:ExtHandlerAdd a sub-handler to this handler. Some handler types do not utilize sub-handlers.- Overrides:
addHandlerin classExtHandler- Parameters:
handler- the handler to add- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
addHandler
public void addHandler(Handler handler, boolean replay) throws SecurityException
Add the given handler, optionally atomically replaying the queue, allowing the delegate handler to receive all queued messages as well as all subsequent messages with no loss or reorder in between.- Parameters:
handler- the handler to add (must not benull)replay-trueto replay the prior messages, orfalseto add the handler without replaying- Throws:
SecurityException- if the handler was not allowed to be added
-
getQueue
public ExtLogRecord[] getQueue()
Get a copy of the queue as it is at an exact moment in time.- Returns:
- the copy of the queue
-
getQueueAsStrings
public String[] getQueueAsStrings()
Get a copy of the queue, rendering each record as a string.- Returns:
- the copy of the queue rendered as strings
-
replay
public void replay()
Replay the stored queue to the nested handlers.
-
-