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?

1 Answer 1


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


namespace Drupal\Tests\my_module\Functional;

use Drupal\Tests\BrowserTestBase;

 * My browser tests.
class MyBrowserTest extends BrowserTestBase {

   * {@inheritdoc}
  protected function setUp() {


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


    $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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.