diff --git a/core/lib/Drupal/Core/Database/Log.php b/core/lib/Drupal/Core/Database/Log.php
index bf142c2..6a338d4 100644
--- a/core/lib/Drupal/Core/Database/Log.php
+++ b/core/lib/Drupal/Core/Database/Log.php
@@ -143,6 +143,17 @@ public function log(StatementInterface $statement, $args, $time) {
    */
   public function findCaller() {
     $stack = debug_backtrace();
+
+    // Drop all stack entries before and including methods from the database
+    // connection class.
+    $connection_class = get_class(Database::getConnection($this->connectionKey));
+    while ((!empty($stack[0]['class']) ? $stack[0]['class'] : '') !== $connection_class) {
+      array_shift($stack);
+    }
+    while ((!empty($stack[0]['class']) ? $stack[0]['class'] : '') === $connection_class) {
+      array_shift($stack);
+    }
+
     for ($i = 0, $stack_count = count($stack); $i < $stack_count; ++$i) {
       // If the call was made from a function, 'class' will be empty. It's
       // just easier to give it a default value than to try and integrate
