Class 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.

    • 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<StringstopInterception()
        Stops interception for this thread, clears the message queue, and returns the list of messages
        Returns:
        The list of log messages received