java.lang.Object
java.util.logging.Handler
com.aoapps.hodgepodge.logging.QueuedHandler
An implementation of
Handler
that 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 ConsoleHandler
via
HandlerUtil.configure(java.util.logging.Handler)
.
- Author:
- AO Industries, Inc.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
QueuedHandler
(String executorThreadName) Manages the queue internally.protected
QueuedHandler
(ExecutorService executor) Uses the provided executor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
backgroundPublish
(Formatter formatter, LogRecord rec, String fullReport) This is called in a background thread.void
close()
void
flush()
TODO: Could wait until all queued log records up to this moment have been handled.protected static ExecutorService
newExecutor
(String executorThreadName) Creates a new executor.void
protected static void
shutdownExecutor
(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 Details
-
Method Details
-
newExecutor
Creates a new executor. Must be shutdown when no longer needed. -
shutdownExecutor
Shuts down the executor, waiting up to one minute for tasks to complete.- Throws:
SecurityException
-
publish
-
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
- Specified by:
close
in classHandler
- Throws:
SecurityException
-
backgroundPublish
protected abstract void backgroundPublish(Formatter formatter, LogRecord rec, String fullReport) throws Exception This is called in a background thread.- Parameters:
formatter
- the formatter at the time the record was queuedrec
- 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
-