Class LogCollectorHandler

java.lang.Object
java.util.logging.Handler
org.glassfish.main.jul.handler.LogCollectorHandler

public class LogCollectorHandler extends Handler
This special Handler can be used for testing purposes. It collects log records passing through the given Logger instance.
Author:
David Matejcek
  • Constructor Details

    • LogCollectorHandler

      public LogCollectorHandler(Logger loggerToFollow)
      Parameters:
      loggerToFollow - this handler will be added to this logger.
  • Method Details

    • publish

      public void publish(LogRecord record)
      Specified by:
      publish in class Handler
    • flush

      public void flush()
      Specified by:
      flush in class Handler
    • close

      public void close() throws SecurityException
      Unattaches the handler from the logger and drops all collected log records.
      Specified by:
      close in class Handler
      Throws:
      SecurityException
    • pop

      public GlassFishLogRecord pop()
      Removes the first record in the buffer and returns it.
      Returns:
      the first GlassFishLogRecord in the buffer or null if the buffer is empty.
    • getAll

      public List<GlassFishLogRecord> getAll()
      Creates a list of all records and resets the buffer.
      Returns:
      all collected records
    • getAll

      public <R> List<R> getAll(Function<LogRecord,R> mappingFunction)
      Creates a list of all records and resets the buffer.
      Type Parameters:
      R - expected item type
      Parameters:
      mappingFunction -
      Returns:
      all collected records
    • reset

      public void reset()
      Drops all collected records.