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.
Determine the routine that called this query.
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, $args, $time)
Log a query to all active logging keys.
This
findCaller()
Determine the routine that called this query.
We define "the routine that called this query" as the first entry in the call stack that is not inside the includes/Drupal/Database directory, does not begin with db_ 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.