Class LogCapture
- java.lang.Object
-
- com.identityworksllc.iiq.common.logging.LogCapture
-
public class LogCapture extends Object
A class to start and stop log capture as needed.Start interception at any point by calling
startInterception(String...)
, passing one or more logger names. If no logger names are passed, a predefined set of common ones will be used.All messages down to DEBUG level will be captured, even if the logger is set to a higher level. Existing appenders will be copied and adjusted so that they continue to log at the previous level. In other words, you’ll get DEBUG messages intercepted but they won’t end up in your actual log file.
When you’re done, make sure to call
stopInterception()
or you will have a definite memory leak. You will get back your log messages as a list of strings.For a streaming experience, you can register a LogListener with the other version of
startInterception(LogListener, String...)
. This listener will receive all log messages as instances of LogListener.LogMessage.
-
-
Field Summary
Fields Modifier and Type Field Description static ThreadLocal<LogListener>
listener
The log message listener for this thread; if a listener is defined, no messages will be storedstatic ThreadLocal<List<String>>
messages
The log messages captured for this thread
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addLoggers(String... loggerNames)
Adds logger interceptors for the given loggers if they don’t already have anystatic void
setListener(LogListener _listener)
Sets the log listener for the current thread to the given listener object.static void
startInterception(LogListener _listener, String... loggers)
Starts log interception if it hasn’t already been startedstatic void
startInterception(String... loggers)
Starts log interception if it hasn’t already been startedstatic List<String>
stopInterception()
Stops interception for this thread, clears the message queue, and returns the list of messages
-
-
-
Field Detail
-
listener
public static ThreadLocal<LogListener> listener
The log message listener for this thread; if a listener is defined, no messages will be stored
-
messages
public static ThreadLocal<List<String>> messages
The log messages captured for this thread
-
-
Method Detail
-
addLoggers
public static void addLoggers(String... loggerNames) throws sailpoint.tools.GeneralException
Adds logger interceptors for the given loggers if they don’t already have any- Parameters:
loggerNames
- The logger names to intercept- Throws:
sailpoint.tools.GeneralException
- If a reflection exception occurs
-
setListener
public static void setListener(LogListener _listener)
Sets the log listener for the current thread to the given listener object.The existing message queue will be retrieved, dumped to the listener, then disabled.
- Parameters:
_listener
- The listener to assign
-
startInterception
public static void startInterception(LogListener _listener, String... loggers) throws sailpoint.tools.GeneralException
Starts log interception if it hasn’t already been started- Throws:
sailpoint.tools.GeneralException
- on reflection failure setting up the logging interceptor
-
startInterception
public static void startInterception(String... loggers) throws sailpoint.tools.GeneralException
Starts log interception if it hasn’t already been started- Throws:
sailpoint.tools.GeneralException
- on reflection failure setting up the logging interceptor
-
stopInterception
public static List<String> stopInterception()
Stops interception for this thread, clears the message queue, and returns the list of messages- Returns:
- The list of log messages received
-
-