summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-10-15 11:26:06 -0700
committerBrion Vibber <brion@pobox.com>2010-10-15 11:26:06 -0700
commita7d98435f649da268f728825e64eb673c451e242 (patch)
tree2ea68dd85f9c35d71d748a8efe10197f9ba0dc77
parent0721d8d3e257709d27994eb4ab4bbe60abc93e2e (diff)
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. :)
-rw-r--r--classes/Memcached_DataObject.php18
1 files changed, 16 insertions, 2 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 8ffb46cc5..27bb5d3c9 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -338,13 +338,27 @@ class Memcached_DataObject extends Safe_DataObject
}
$start = microtime(true);
- $result = parent::_query($string);
+ $fail = false;
+ try {
+ $result = parent::_query($string);
+ } catch (Exception $e) {
+ $fail = $e;
+ }
$delta = microtime(true) - $start;
$limit = common_config('db', 'log_slow_queries');
if (($limit > 0 && $delta >= $limit) || common_config('db', 'log_queries')) {
$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;
}