Skip to content

Commit

Permalink
add option to add backtrace to the query logger
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and AndyScherzinger committed Feb 27, 2024
1 parent 250084f commit a42668a
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 @@ -367,6 +367,12 @@ protected function logQueryToFile(string $sql): void {
if ($this->systemConfig->getValue('query_log_file_requestid') === 'yes') {
$prefix .= \OC::$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 @@ -375,7 +381,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 a42668a

Please sign in to comment.