Skip to content

Commit 7827001

Browse files
committed
feat: add option to add backtrace to the query logger
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 4177e8a commit 7827001

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/private/DB/Connection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ protected function logQueryToFile(string $sql): void {
367367
if ($this->systemConfig->getValue('query_log_file_requestid') === 'yes') {
368368
$prefix .= \OC::$server->get(IRequestId::class)->getId() . "\t";
369369
}
370+
$postfix = '';
371+
if ($this->systemConfig->getValue('query_log_file_backtrace') === 'yes') {
372+
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
373+
array_pop($trace);
374+
$postfix .= '; ' . json_encode($trace);
375+
}
370376

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

376382
file_put_contents(
377383
$this->systemConfig->getValue('query_log_file', ''),
378-
$prefix . $sql . "\n",
384+
$prefix . $sql . $postfix . "\n",
379385
FILE_APPEND
380386
);
381387
}

0 commit comments

Comments
 (0)