- java.lang.Object
-
- java.util.logging.Handler
-
- de.carne.util.logging.LogBuffer
-
public class LogBuffer extends java.util.logging.HandlerHandler implementation used to add/remove Handler instances programmatically during application runtime. This class keeps a buffer of published LogRecords to make them available to added Handler instances (e.g. to display log messages issued during application startup in UI).
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddHandler(Log log, java.util.logging.Handler handler, boolean republishBuffer)Adds a Handler to this LogBuffer instance for LogRecord consuming.voidaddHandler(java.util.logging.Handler handler, boolean republishBuffer)Adds a Handler to this LogBuffer instance for LogRecord consuming.static voidaddHandler(java.util.logging.Logger logger, java.util.logging.Handler handler, boolean republishBuffer)Adds a Handler to this LogBuffer instance for LogRecord consuming.voidclose()static voidexportTo(Log log, java.io.File file, boolean append)Exports the buffered LogRecords to a File.voidexportTo(java.io.File file, boolean append)Exports the buffered LogRecords to a File.static voidexportTo(java.util.logging.Logger logger, java.io.File file, boolean append)Exports the buffered LogRecords to a File.voidflush()static voidflush(Log log)Performs a flush operation on this LogBuffer instance.static voidflush(java.util.logging.Logger logger)Performs a flush operation on this LogBuffer instance.static @Nullable LogBufferget(Log log)static @Nullable LogBufferget(java.util.logging.Logger logger)Gets the LogBuffer attached to the submitted Logger (if any).static <T extends java.util.logging.Handler>
@Nullable TgetHandler(Log log, java.lang.Class<T> handlerType)Gets a previously registered Handler of a specific type.<T extends java.util.logging.Handler>
@Nullable TgetHandler(java.lang.Class<T> handlerType)Gets a previously registered Handler of a specific type.static <T extends java.util.logging.Handler>
@Nullable TgetHandler(java.util.logging.Logger logger, java.lang.Class<T> handlerType)Gets a previously registered Handler of a specific type.voidpublish(@Nullable java.util.logging.LogRecord logRecord)static voidremoveHandler(Log log, java.util.logging.Handler handler)Removes a previously added Handler from this LogBuffer instance.voidremoveHandler(java.util.logging.Handler handler)Removes a previously added Handler from this LogBuffer instance.static voidremoveHandler(java.util.logging.Logger logger, java.util.logging.Handler handler)Removes a previously added Handler from this LogBuffer instance.
-
-
-
Constructor Detail
-
LogBuffer
public LogBuffer()
Constructs a new LogBuffer instance.
-
-
Method Detail
-
get
public static @Nullable LogBuffer get(java.util.logging.Logger logger)
Gets the LogBuffer attached to the submitted Logger (if any).
-
addHandler
public static void addHandler(Log log, java.util.logging.Handler handler, boolean republishBuffer)
Adds a Handler to this LogBuffer instance for LogRecord consuming.If the submitted Log has no LogBuffer attached the call is ignored.
- Parameters:
log- the Log identifying the LogBuffer to add to.handler- the Handler to add.republishBuffer- whether to republish buffered LogRecords to the Handler.- See Also:
get(Log),addHandler(Handler, boolean)
-
addHandler
public static void addHandler(java.util.logging.Logger logger, java.util.logging.Handler handler, boolean republishBuffer)Adds a Handler to this LogBuffer instance for LogRecord consuming.If the submitted Logger has no LogBuffer attached the call is ignored.
- Parameters:
logger- the Logger identifying the LogBuffer to add to.handler- the Handler to add.republishBuffer- whether to republish buffered LogRecords to the Handler.- See Also:
get(Logger),addHandler(Handler, boolean)
-
addHandler
public void addHandler(java.util.logging.Handler handler, boolean republishBuffer)Adds a Handler to this LogBuffer instance for LogRecord consuming.Any already buffered LogRecord is sent to the Handler during this operation.
- Parameters:
handler- the Handler to add.republishBuffer- whether to republish buffered LogRecords to the Handler.
-
getHandler
public static <T extends java.util.logging.Handler> @Nullable T getHandler(Log log, java.lang.Class<T> handlerType)
-
getHandler
public static <T extends java.util.logging.Handler> @Nullable T getHandler(java.util.logging.Logger logger, java.lang.Class<T> handlerType)Gets a previously registered Handler of a specific type. If the submitted Logger has no LogBuffer attached the call is ignored.- Type Parameters:
T- the actual type of the requested Handler.- Parameters:
logger- the Logger identifying the LogBuffer to search.handlerType- the type of Handler to get.- Returns:
- the found Handler or
null.
-
getHandler
public <T extends java.util.logging.Handler> @Nullable T getHandler(java.lang.Class<T> handlerType)
Gets a previously registered Handler of a specific type.- Type Parameters:
T- the actual type of the requested Handler.- Parameters:
handlerType- the type of Handler to get.- Returns:
- the found Handler or
null.
-
removeHandler
public static void removeHandler(Log log, java.util.logging.Handler handler)
Removes a previously added Handler from this LogBuffer instance.If the submitted Log has no LogBuffer attached the call is ignored.
- Parameters:
log- the Log identifying the LogBuffer to remove from.handler- the Handler to remove.- See Also:
addHandler(Log, Handler, boolean),get(Log),removeHandler(Handler)
-
removeHandler
public static void removeHandler(java.util.logging.Logger logger, java.util.logging.Handler handler)Removes a previously added Handler from this LogBuffer instance.If the submitted Logger has no LogBuffer attached the call is ignored.
- Parameters:
logger- the Logger identifying the LogBuffer to remove from.handler- the Handler to remove.- See Also:
addHandler(Logger, Handler, boolean),get(Logger),removeHandler(Handler)
-
removeHandler
public void removeHandler(java.util.logging.Handler handler)
Removes a previously added Handler from this LogBuffer instance.After removal the Handler will no longer receive any LogRecords.
- Parameters:
handler- the Handler to remove.- See Also:
addHandler(Handler, boolean)
-
exportTo
public static void exportTo(Log log, java.io.File file, boolean append) throws java.io.IOException
-
exportTo
public static void exportTo(java.util.logging.Logger logger, java.io.File file, boolean append) throws java.io.IOExceptionExports the buffered LogRecords to a File.If the submitted Logger has no LogBuffer attached the call is ignored.
- Parameters:
logger- the Logger identifying the LogBuffer to export from.file- the File to export to.append- whether to append (true) in case of an existing file or not (false).- Throws:
java.io.IOException- if an I/O error occurs during export.
-
exportTo
public void exportTo(java.io.File file, boolean append) throws java.io.IOExceptionExports the buffered LogRecords to a File.- Parameters:
file- the File to export to.append- whether to append (true) in case of an existing file or not (false).- Throws:
java.io.IOException- if an I/O error occurs during export.
-
flush
public static void flush(Log log)
-
flush
public static void flush(java.util.logging.Logger logger)
Performs a flush operation on this LogBuffer instance.The flush request is forwarded to any currently registered Handler and any buffered LogRecord will be discarded. If the submitted Logger has no LogBuffer attached the call is ignored.
- Parameters:
logger- the Logger identifying the LogBuffer to flush.- See Also:
get(Logger)
-
publish
public void publish(@Nullable java.util.logging.LogRecord logRecord)
- Specified by:
publishin classjava.util.logging.Handler
-
flush
public void flush()
- Specified by:
flushin classjava.util.logging.Handler
-
close
public void close()
- Specified by:
closein classjava.util.logging.Handler
-
-