Skip to content

Commit d6be80c

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

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/private/DB/Connection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ protected function logQueryToFile(string $sql): void {
370370
if ($this->systemConfig->getValue('query_log_file_requestid') === 'yes') {
371371
$prefix .= Server::get(IRequestId::class)->getId() . "\t";
372372
}
373+
$postfix = '';
374+
if ($this->systemConfig->getValue('query_log_file_backtrace') === 'yes') {
375+
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
376+
array_pop($trace);
377+
$postfix .= '; ' . json_encode($trace);
378+
}
373379

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

379385
file_put_contents(
380386
$this->systemConfig->getValue('query_log_file', ''),
381-
$prefix . $sql . "\n",
387+
$prefix . $sql . $postfix . "\n",
382388
FILE_APPEND
383389
);
384390
}

0 commit comments

Comments
 (0)