# Capturing log messages

Capture log messages during test execution, appending them to the error reports of failed tests.

This plugin implements `startTestRun()`, `startTest()`, `stopTest()`, `setTestOutcome()`, and `outcomeDetail()` to set up a logging configuration that captures log messages during test execution, and appends them to error reports for tests that fail or raise exceptions.

## Configuration [log-capture]

always-on
  Default:

    False

  Type:

    boolean

clear-handlers
  Default:

    False

  Type:

    boolean

date-format
  Default:

    None

  Type:

    str

filter
  Default:

    [‘-nose’]

  Type:

    list

format
  Default:

    %(name)s: %(levelname)s: %(message)s

  Type:

    str

log-level
  Default:

    NOTSET

  Type:

    str

### Sample configuration

The default configuration is equivalent to including the following in a `unittest.cfg` file.

    [log-capture]
    always-on = False
    clear-handlers = False
    filter = -nose
    format = %(name)s: %(levelname)s: %(message)s
    log-level = NOTSET

## Command-line options

--log-capture DEFAULT

  Enable log capture

## Plugin class reference: LogCapture

class nose2.plugins.logcapture.LogCapture(*args, **kwargs)

  Capture log messages during test execution

  outcomeDetail(event)

    Append captured log messages to `event.extraDetail`

  setTestOutcome(event)

    Store captured log messages in `event.metadata`

  startTest(event)

    Set up handler for new test

  startTestRun(event)

    Set up logging handler

  stopTest(event)

    Clear captured messages, ready for next test