diff options
author | Kate <26026535+provokateurin@users.noreply.github.com> | 2025-04-24 12:56:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-24 12:56:11 +0200 |
commit | 85b43f62a3f98ea5aef20a749573e771a73ad8fd (patch) | |
tree | 76fd797c8384a4646a026384aea5ce1cb19b1438 | |
parent | 43c5232333442eec5e8fb062850252a9c27d7c11 (diff) | |
parent | 2ca168f717f75851f6c64446d060f37a18c03e6a (diff) | |
download | nextcloud-server-85b43f62a3f98ea5aef20a749573e771a73ad8fd.tar.gz nextcloud-server-85b43f62a3f98ea5aef20a749573e771a73ad8fd.zip |
Merge pull request #52276 from nextcloud/feat/noid/log-query-parameters
-rw-r--r-- | config/config.sample.php | 22 | ||||
-rw-r--r-- | lib/private/DB/Connection.php | 11 |
2 files changed, 30 insertions, 3 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index ddd91d84a3e..f9943ddfe19 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2586,6 +2586,28 @@ $CONFIG = [ 'query_log_file' => '', /** + * Prefix all queries with the requestid when set to `yes` + * + * Requires `query_log_file` to be set. + */ +'query_log_file_requestid' => '', + +/** + * Add all query parameters to the query log entry when set to `yes` + * + * Requires `query_log_file` to be set. + * Warning: This will log sensitive data into a plain text file. + */ +'query_log_file_parameters' => '', + +/** + * Add a backtrace to the query log entry when set to `yes` + * + * Requires `query_log_file` to be set. + */ +'query_log_file_backtrace' => '', + +/** * Log all redis requests into a file * * Warning: This heavily decreases the performance of the server and is only diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index eecf83ace95..96dd578b2ef 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -414,7 +414,7 @@ class Connection extends PrimaryReadReplicaConnection { $sql = $this->finishQuery($sql); $this->queriesExecuted++; - $this->logQueryToFile($sql); + $this->logQueryToFile($sql, $params); try { return parent::executeQuery($sql, $params, $types, $qcp); } catch (\Exception $e) { @@ -461,7 +461,7 @@ class Connection extends PrimaryReadReplicaConnection { } $sql = $this->finishQuery($sql); $this->queriesExecuted++; - $this->logQueryToFile($sql); + $this->logQueryToFile($sql, $params); try { return (int)parent::executeStatement($sql, $params, $types); } catch (\Exception $e) { @@ -470,14 +470,19 @@ class Connection extends PrimaryReadReplicaConnection { } } - protected function logQueryToFile(string $sql): void { + protected function logQueryToFile(string $sql, array $params): void { $logFile = $this->systemConfig->getValue('query_log_file'); if ($logFile !== '' && is_writable(dirname($logFile)) && (!file_exists($logFile) || is_writable($logFile))) { $prefix = ''; if ($this->systemConfig->getValue('query_log_file_requestid') === 'yes') { $prefix .= Server::get(IRequestId::class)->getId() . "\t"; } + $postfix = ''; + if ($this->systemConfig->getValue('query_log_file_parameters') === 'yes') { + $postfix .= '; ' . json_encode($params); + } + if ($this->systemConfig->getValue('query_log_file_backtrace') === 'yes') { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); array_pop($trace); |