You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by "Paul Rogers (JIRA)" <ji...@apache.org> on 2017/01/18 17:10:26 UTC

[jira] [Created] (DRILL-5203) Provide per-test control over logging for unit tests

Paul Rogers created DRILL-5203:
----------------------------------

             Summary: Provide per-test control over logging for unit tests
                 Key: DRILL-5203
                 URL: https://issues.apache.org/jira/browse/DRILL-5203
             Project: Apache Drill
          Issue Type: Improvement
          Components: Tools, Build & Test
    Affects Versions: 1.9.0
            Reporter: Paul Rogers
            Assignee: Paul Rogers
            Priority: Minor


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:

{code}
  @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
  }
{code}

Alternatively, the settings can affect an entire test class:

{code}
  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();
  }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)