Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-5203

Provide per-test control over logging for unit tests

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.9.0
    • None
    • Tools, Build & Test
    • None

    Description

      Drill provides extensive logging. In production, users typically turn on all logging to some useful level, say WARN for normal operation or DEBUG when problems occur.

      Drill has a wide variety of unit tests, each of which covers some particular part of the product. When working in that area, we wish to turn on logging just for that one area, and often just for the test being used to drive development (in Test-Driven Development fashion.)

      Today, we control logging only via the single, shared logback.xml file in $DRILL_HOME/conf in production, and the logback-test.xml file in the src/resources directory during development. This is a very blunt tool: it affects all tests and is cumbersome to use on a per-test basis.

      This, then is the motivation for a "log fixture": a simple piece of code that lets us turn on very targeted logging for the duration of a single test, then restore the defaults afterwards.

      Example:

        @Test
        public void testSomething() throws Exception {
          LogFixtureBuilder logBuilder = LogFixture.builder()
              .toConsole()
              .disable() // Turn off all logging...
              // Except for this one logger
              .logger(ExternalSortBatch.class, Level.DEBUG);
          try (LogFixture logs = logBuilder.build()) {
            // Do the test here: the one logger is set to debug to the console
          }
          // Logging back to configured settings
        }
      

      Alternatively, the settings can affect an entire test class:

        private static LogFixture logFixture;
        @BeforeClass
        public static void setup() {
          logFixture = LogFixture.builder()
              .toConsole()
              .disable()
              .logger(ExternalSortBatch.class, Level.DEBUG)
              .build();
        }
      
        @AfterClass
        public void tearDown() {
          logFixture.close();
        }
      

      Attachments

        Activity

          People

            paul-rogers Paul Rogers
            paul-rogers Paul Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: