Browse Source

feat(db): Make dirty query logging available in production

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
tags/v29.0.0beta1
Christoph Wurst 4 months ago
parent
commit
911ab393c0
No account linked to committer's email address
2 changed files with 18 additions and 1 deletions
  1. 9
    0
      config/config.sample.php
  2. 9
    1
      lib/private/DB/Connection.php

+ 9
- 0
config/config.sample.php View 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

+ 9
- 1
lib/private/DB/Connection.php View 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);

Loading…
Cancel
Save