Tweak DB query logging to also log queries that fail; the exceptions we get are often not very descriptive like "No such table" without saying which table. :)
This commit is contained in:
parent
0721d8d3e2
commit
a7d98435f6
@ -338,13 +338,27 @@ class Memcached_DataObject extends Safe_DataObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
$fail = false;
|
||||||
|
try {
|
||||||
$result = parent::_query($string);
|
$result = parent::_query($string);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$fail = $e;
|
||||||
|
}
|
||||||
$delta = microtime(true) - $start;
|
$delta = microtime(true) - $start;
|
||||||
|
|
||||||
$limit = common_config('db', 'log_slow_queries');
|
$limit = common_config('db', 'log_slow_queries');
|
||||||
if (($limit > 0 && $delta >= $limit) || common_config('db', 'log_queries')) {
|
if (($limit > 0 && $delta >= $limit) || common_config('db', 'log_queries')) {
|
||||||
$clean = $this->sanitizeQuery($string);
|
$clean = $this->sanitizeQuery($string);
|
||||||
common_log(LOG_DEBUG, sprintf("DB query (%0.3fs): %s", $delta, $clean));
|
if ($fail) {
|
||||||
|
$msg = sprintf("FAILED DB query (%0.3fs): %s - %s", $delta, $fail->getMessage(), $clean);
|
||||||
|
} else {
|
||||||
|
$msg = sprintf("DB query (%0.3fs): %s", $delta, $clean);
|
||||||
|
}
|
||||||
|
common_log(LOG_DEBUG, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fail) {
|
||||||
|
throw $fail;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user