function Database::startLog

Same name in other branches
  1. 7.x includes/database/database.inc \Database::startLog()
  2. 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::startLog()
  3. 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::startLog()
  4. 11.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::startLog()

Starts logging a given logging key on the specified connection.

Parameters

string $logging_key: The logging key to log.

string $key: The database connection key for which we want to log.

Return value

\Drupal\Core\Database\Log The query log object. Note that the log object does support richer methods than the few exposed through the Database class, so in some cases it may be desirable to access it directly.

See also

\Drupal\Core\Database\Log

7 calls to Database::startLog()
EndOfTransactionQueriesTest::testEntitySave in core/tests/Drupal/KernelTests/Core/Cache/EndOfTransactionQueriesTest.php
Tests an entity save.
LoggingTest::testEnableLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests that we can log the existence of a query.
LoggingTest::testEnableMultiConnectionLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests that we can log queries separately on different connections.
LoggingTest::testEnableMultiLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests that we can run two logs in parallel.
LoggingTest::testEnableTargetLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests logging queries against multiple targets on the same connection.

... See full list

File

core/lib/Drupal/Core/Database/Database.php, line 119

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static final function startLog($logging_key, $key = 'default') {
    if (empty(self::$logs[$key])) {
        self::$logs[$key] = new Log($key);
        // Every target already active for this connection key needs to have the
        // logging object associated with it.
        if (!empty(self::$connections[$key])) {
            foreach (self::$connections[$key] as $connection) {
                $connection->enableEvents(StatementEvent::all());
                $connection->setLogger(self::$logs[$key]);
            }
        }
    }
    self::$logs[$key]->start($logging_key);
    return self::$logs[$key];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.