How can I capture Watchdog output during a functional test? I have a functional test that is failing, and I think that there could be some useful information in the database log, but unfortunately the test suite only runs in containers on GitLab CI so I don't have any way to get to the database log while the environment is running.
Is there any easy way to get a dump of the contents of the watchdog log in a test artifact?
The Watchdog to File module is handy for this use case. You can initialize it in a test setup, like so:
&lt;?php

namespace Drupal\Tests\my_module\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * My browser tests.
 */
class MyBrowserTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this-&gt;enableFileLogging();
  }

  /**
   * Enables logging of ALL watchdog events to a file.
   */
  protected function enableFileLogging() {
    $installer = \Drupal::service('module_installer');

    $installer-&gt;install([
      'watchdog_file',
    ]);

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

    $log_path =
      sprintf(
        '%s/artifacts/watchdog-%s.log',
        dirname(DRUPAL_ROOT),
        $this-&gt;databasePrefix
      );

    $config-&gt;set('log_filename', $log_path);
    $config-&gt;save(TRUE);
  }

}

Then, just configure GitLab CI to capture the test artifacts folder:
  artifacts:
    when: always
    reports:
      junit: artifacts/junit/*.xml
    paths:
      - 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 will 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.