]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(db): Make dirty query logging available in production 43185/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Mon, 29 Jan 2024 10:41:45 +0000 (11:41 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 30 Jan 2024 09:31:03 +0000 (10:31 +0100)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
config/config.sample.php
lib/private/DB/Connection.php

index 24bed544692261840bf0bfd745e562f044eec8c8..d999b1e39b0b04187717384cc19da959a8358565 100644 (file)
@@ -994,6 +994,15 @@ $CONFIG = [
  */
 'loglevel_frontend' => 2,
 
+/**
+ * Loglevel used by the dirty database query detection. Useful to identify
+ * potential database bugs in production. Set this to loglevel or higher to
+ * see dirty queries in the logs.
+ *
+ * Defaults to ``0`` (debug)
+ */
+'loglevel_dirty_database_queries' => 0,
+
 /**
  * If you maintain different instances and aggregate the logs, you may want
  * to distinguish between them. ``syslog_tag`` can be set per instance
index 09c321aedb823052c0c534552219d92f79ad3197..5affa2c3d487766ae0e14c73445e0e4a2fe07c0c 100644 (file)
@@ -276,7 +276,15 @@ class Connection extends PrimaryReadReplicaConnection {
                } else {
                        // Read to a table that has been written to previously
                        // While this might not necessarily mean that we did a read after write it is an indication for a code path to check
-                       $this->logger->debug('dirty table reads: ' . $sql, ['tables' => $this->tableDirtyWrites, 'reads' => $tables, 'exception' => new \Exception()]);
+                       $this->logger->log(
+                               (int) ($this->systemConfig->getValue('loglevel_dirty_database_queries', null) ?? 0),
+                               'dirty table reads: ' . $sql,
+                               [
+                                       'tables' => $this->tableDirtyWrites,
+                                       'reads' => $tables,
+                                       'exception' => new \Exception(),
+                               ],
+                       );
                }
 
                $sql = $this->replaceTablePrefix($sql);