testing – How can I capture Watchdog output during a Drupal 8 functional test?

The Watchdog to File module is handy for this use case. You can initialize it in a test setup, like so:


namespace DrupalTestsmy_moduleFunctional;

use DrupalTestsBrowserTestBase;

 * My browser tests.
class MyBrowserTest extends BrowserTestBase {

   * {@inheritdoc}
  protected function setUp() {


   * Enables logging of watchdog output.
  protected function enableFileLogging() {
    $installer = Drupal::service('module_installer');

    // Enable logging ALL watchdog events to standard out.

    $config_factory = Drupal::configFactory();
    $config         = $config_factory->getEditable('watchdog_file.settings');

    $log_path =

    $config->set('log_filename', $log_path);


Then, just configure GitLab CI to capture the test artifacts folder:

    when: always
      junit: artifacts/junit/*.xml
      - artifacts/*
      - web/sites/simpletest/*

As a bonus, the above snippet also captures browser output produced by browser tests, in case you need to review them as well.

Each watchdog log should be named according to the Simple Test database ID that is used for the corresponding test run. For example, if you have five cases in your test, you should end up with five watchdog file logs.