From 911ab393c07d7e2f29e8949d422b122ca91be354 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 29 Jan 2024 11:41:45 +0100 Subject: [PATCH] feat(db): Make dirty query logging available in production Signed-off-by: Christoph Wurst --- config/config.sample.php | 9 +++++++++ lib/private/DB/Connection.php | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config/config.sample.php b/config/config.sample.php index 24bed544692..d999b1e39b0 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -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 diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 09c321aedb8..5affa2c3d48 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -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); -- 2.39.5