Package com.aoindustries.util.logging
Class QueuedHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- com.aoindustries.util.logging.QueuedHandler
-
public abstract class QueuedHandler extends Handler
An implementation of
Handlerthat queues log records and handles them in the background. The log records are processed in the order received, regardless of level.Configures itself similar to
ConsoleHandlerviaHandlerUtil.configure(java.util.logging.Handler).- Author:
- AO Industries, Inc.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueuedHandler(String executorThreadName)Manages the queue internally.protectedQueuedHandler(ExecutorService executor)Uses the provided executor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidbackgroundPublish(Formatter formatter, LogRecord record, String fullReport)This is called in a background thread.voidclose()voidflush()TODO: Could wait until all queued log records up to this moment have been handled.protected static ExecutorServicenewExecutor(String executorThreadName)Creates a new executor.voidpublish(LogRecord record)protected static voidshutdownExecutor(ExecutorService executor)Shuts down the executor, waiting up to one minute for tasks to complete.-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
-
-
-
Constructor Detail
-
QueuedHandler
protected QueuedHandler(String executorThreadName)
Manages the queue internally.
-
QueuedHandler
protected QueuedHandler(ExecutorService executor)
-
-
Method Detail
-
newExecutor
protected static ExecutorService newExecutor(String executorThreadName)
Creates a new executor. Must be shutdown when no longer needed.
-
shutdownExecutor
protected static void shutdownExecutor(ExecutorService executor) throws SecurityException
Shuts down the executor, waiting up to one minute for tasks to complete.- Throws:
SecurityException
-
publish
public void publish(LogRecord record)
- Specified by:
publishin classHandler- See Also:
StreamHandler.publish(java.util.logging.LogRecord)
-
flush
public void flush()
TODO: Could wait until all queued log records up to this moment have been handled. If new log records are added while we wait, don't wait for them.
-
close
public void close() throws SecurityException- Specified by:
closein classHandler- Throws:
SecurityException
-
backgroundPublish
protected abstract void backgroundPublish(Formatter formatter, LogRecord record, String fullReport) throws Exception
This is called in a background thread.- Parameters:
formatter- the formatter at the time the record was queuedrecord- the queued recordfullReport- the complete message generated by the formatter before the record was queued. The message is generated before so it can have accurate thread and time information.- Throws:
Exception
-
-