Skip to content

Commit

Permalink
Merge pull request #39247 from nextcloud/query-log-backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored May 2, 2024
2 parents 630d6d7 + d6be80c commit d4a6a70
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ protected function logQueryToFile(string $sql): void {
if ($this->systemConfig->getValue('query_log_file_requestid') === 'yes') {
$prefix .= Server::get(IRequestId::class)->getId() . "\t";
}
$postfix = '';
if ($this->systemConfig->getValue('query_log_file_backtrace') === 'yes') {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
array_pop($trace);
$postfix .= '; ' . json_encode($trace);
}

// FIXME: Improve to log the actual target db host
$isPrimary = $this->connections['primary'] === $this->_conn;
Expand All @@ -378,7 +384,7 @@ protected function logQueryToFile(string $sql): void {

file_put_contents(
$this->systemConfig->getValue('query_log_file', ''),
$prefix . $sql . "\n",
$prefix . $sql . $postfix . "\n",
FILE_APPEND
);
}
Expand Down

0 comments on commit d4a6a70

Please sign in to comment.