Log
class Log (View source)
Database query logger.
We log queries in a separate object rather than in the connection object because we want to be able to see all queries sent to a given database, not database target. If we logged the queries in each connection object we would not be able to track what queries went to which target.
Every connection has one and only one logging object on it for all targets and logging keys.
Properties
| protected array | $queryLog | Cache of logged queries. This will only be used if the query logger is enabled. |
|
| protected string | $connectionKey | The connection key for which this object is logging. |
Methods
Constructor.
Begin logging queries to the specified connection and logging key.
Retrieve the query log for the specified logging key so far.
Empty the query log for the specified logging key.
Stop logging for the specified logging key.
Log a query to all active logging keys.
Determine the routine that called this query.
Removes database related calls from a backtrace array.
Gets the debug backtrace.
Details
__construct($key = 'default')
Constructor.
start($logging_key)
Begin logging queries to the specified connection and logging key.
If the specified logging key is already running this method does nothing.
An
get($logging_key)
Retrieve the query log for the specified logging key so far.
clear($logging_key)
Empty the query log for the specified logging key.
This method does not stop logging, it simply clears the log. To stop logging, use the end() method.
end($logging_key)
Stop logging for the specified logging key.
log(StatementInterface $statement, array $args, float $time, float $start = NULL)
Log a query to all active logging keys.
This
findCaller()
Determine the routine that called this query.
Traversing the call stack from the very first call made during the request, we define "the routine that called this query" as the last entry in the call stack that is not any method called from the namespace of the database driver, is not inside the Drupal\Core\Database namespace and does have a file (which excludes call_user_func_array(), anonymous functions and similar). That makes the climbing logic very simple, and handles the variable stack depth caused by the query builders.
See the @link http://php.net/debug_backtrace debug_backtrace() @endlink function.
static array
removeDatabaseEntries(array $backtrace, string $driver_namespace)
Removes database related calls from a backtrace array.
protected array[]
getDebugBacktrace()
Gets the debug backtrace.
Wraps the debug_backtrace function to allow mocking results in PHPUnit tests.