Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,28 @@
*/
'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
*
Expand Down
11 changes: 8 additions & 3 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function executeQuery(string $sql, array $params = [], $types = [], ?Quer

$sql = $this->finishQuery($sql);
$this->queriesExecuted++;
$this->logQueryToFile($sql);
$this->logQueryToFile($sql, $params);
try {
return parent::executeQuery($sql, $params, $types, $qcp);
} catch (\Exception $e) {
Expand Down Expand Up @@ -461,7 +461,7 @@ public function executeStatement($sql, array $params = [], array $types = []): i
}
$sql = $this->finishQuery($sql);
$this->queriesExecuted++;
$this->logQueryToFile($sql);
$this->logQueryToFile($sql, $params);
try {
return (int)parent::executeStatement($sql, $params, $types);
} catch (\Exception $e) {
Expand All @@ -470,14 +470,19 @@ public function executeStatement($sql, array $params = [], array $types = []): i
}
}

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);
Expand Down
Loading