]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Tweak DB query logging to also log queries that fail; the exceptions we get are often...
authorBrion Vibber <brion@pobox.com>
Fri, 15 Oct 2010 18:26:06 +0000 (11:26 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 15 Oct 2010 18:26:06 +0000 (11:26 -0700)
classes/Memcached_DataObject.php

index 8ffb46cc52d5da0e4a4a2b43cf453f3748858da6..27bb5d3c9d6e32f58063f9e1320b5daa711d123f 100644 (file)
@@ -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;
     }