add stacktrace to query logger
This commit is contained in:
parent
8d8366762b
commit
1c3b1e5797
|
@ -34,15 +34,18 @@ class Query implements IQuery {
|
|||
|
||||
private $end;
|
||||
|
||||
private $stack;
|
||||
|
||||
/**
|
||||
* @param string $sql
|
||||
* @param array $params
|
||||
* @param int $start
|
||||
*/
|
||||
public function __construct($sql, $params, $start) {
|
||||
public function __construct($sql, $params, $start, array $stack) {
|
||||
$this->sql = $sql;
|
||||
$this->params = $params;
|
||||
$this->start = $start;
|
||||
$this->stack = $stack;
|
||||
}
|
||||
|
||||
public function end($time) {
|
||||
|
@ -69,4 +72,12 @@ class Query implements IQuery {
|
|||
public function getDuration() {
|
||||
return $this->end - $this->start;
|
||||
}
|
||||
|
||||
public function getStartTime() {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getStacktrace() {
|
||||
return $this->stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,15 @@ class QueryLogger implements IQueryLogger {
|
|||
* @param array $types
|
||||
*/
|
||||
public function startQuery($sql, array $params = null, array $types = null) {
|
||||
$this->activeQuery = new Query($sql, $params, microtime(true));
|
||||
$this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack());
|
||||
}
|
||||
|
||||
private function getStack() {
|
||||
$stack = debug_backtrace();
|
||||
array_shift($stack);
|
||||
array_shift($stack);
|
||||
array_shift($stack);
|
||||
return $stack;
|
||||
}
|
||||
|
||||
public function stopQuery() {
|
||||
|
|
|
@ -47,4 +47,16 @@ interface IQuery {
|
|||
* @since 8.0.0
|
||||
*/
|
||||
public function getDuration();
|
||||
|
||||
/**
|
||||
* @return float
|
||||
* @since 9.2.0
|
||||
*/
|
||||
public function getStartTime();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 9.2.0
|
||||
*/
|
||||
public function getStacktrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue