Class Recorder


  • public class Recorder
    extends java.lang.Object
    Logs recorder. Applies custom appender for logback logger(s) and change level, if required. Collect all log events.
    Since:
    26.02.2025
    • Constructor Summary

      Constructors 
      Constructor Description
      Recorder​(java.lang.String name, org.slf4j.event.Level level, java.util.List<java.lang.String> loggers)
      Create recorder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attach()
      Could be called multiple times.
      void clear()
      Clear recordings.
      void destroy()
      Remove appender from logger.
      RecordedLogs getRecordedLogs()
      Note that object always returns actual logs.
      java.util.List<ch.qos.logback.classic.spi.ILoggingEvent> getRecords()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Recorder

        public Recorder​(java.lang.String name,
                        org.slf4j.event.Level level,
                        java.util.List<java.lang.String> loggers)
        Create recorder.
        Parameters:
        name - name
        level - base level
        loggers - target loggers
    • Method Detail

      • getRecords

        public java.util.List<ch.qos.logback.classic.spi.ILoggingEvent> getRecords()
        Returns:
        raw recorded records
        See Also:
        for easy navigation
      • getRecordedLogs

        public RecordedLogs getRecordedLogs()
        Note that object always returns actual logs. So the same instance could be used to all verifications.
        Returns:
        recorded logs navigation object
      • clear

        public void clear()
        Clear recordings.
      • attach

        public void attach()
        Could be called multiple times. Initially called before application start to record all startup events. But dropwizard reset loggers just before run phase, so appender must be applied second time.

        DON'T call this method manually: simply no need - hook will call it in appropriate moments.

      • destroy

        public void destroy()
        Remove appender from logger.

        Not required as dropwizard reset all logging during application startup and so stale appenders would be removed in any case before each new test.