/** * Add the list of queries run during render to buildinfo. * * @see ViewUI::startQueryCapture() */ public function endQueryCapture() { $queries = Database::getLog('views'); $this->additionalQueries = $queries; }
/** * Tests that we can log queries separately on different connections. */ function testEnableMultiConnectionLogging() { // Clone the primary credentials to a fake connection. // That both connections point to the same physical database is irrelevant. $connection_info = Database::getConnectionInfo('default'); Database::addConnectionInfo('test2', 'default', $connection_info['default']); Database::startLog('testing1'); Database::startLog('testing1', 'test2'); db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol(); $old_key = db_set_active('test2'); db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'replica'))->fetchCol(); db_set_active($old_key); $queries1 = Database::getLog('testing1'); $queries2 = Database::getLog('testing1', 'test2'); $this->assertEqual(count($queries1), 1, 'Correct number of queries recorded for first connection.'); $this->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.'); }
public static final function getLog($logging_key, $key = 'default') { return BaseDatabase::getLog($logging_key, $key); }
/** * Log the termination of a request. * * @param Response $response * @param Request $request */ protected function logResponse(Response $response, Request $request) { $queries = Database::getLog('console_logger', 'default'); $sum = 0; if (!empty($queries)) { foreach ($queries as $query) { $text[] = $query['query']; $sum += $query['time']; } $querySummary = 'Executed {queries} queries in {time_ms} ms.'; $this->logger->log($this->logLevel, $querySummary, ['queries' => count($queries), 'time_ms' => round($sum * 1000, 2)]); } if ($response->headers->has('x-debug-token-link')) { $this->logger->log($this->logLevel, 'Profiler at {url}', ['url' => $GLOBALS['base_url'] . $response->headers->get('x-debug-token-link')]); } }
/** * Tests that getLog with a wrong key return an empty array. */ function testGetLoggingWrongKey() { $result = Database::getLog('wrong'); $this->assertEqual($result, [], 'The function getLog with a wrong key returns an empty array.'); }