aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2025-06-16 11:15:03 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2025-06-16 11:15:03 +0200
commitc9b316b028a1ddbbb77cd3732779681e5fe6d77f (patch)
tree3a7eb7a2febb48ff540a437bdd551772edf19db3
parent9b29df2dd59dffa85a29098d5684900f732ce584 (diff)
downloadnextcloud-server-feat/log/log-session-id.tar.gz
nextcloud-server-feat/log/log-session-id.zip
feat(log): add opt-in session ID loggingfeat/log/log-session-id
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--config/config.sample.php10
-rw-r--r--lib/private/Log.php9
2 files changed, 19 insertions, 0 deletions
diff --git a/config/config.sample.php b/config/config.sample.php
index 947666e0895..f51ba51a897 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -1142,6 +1142,16 @@ $CONFIG = [
'log.backtrace' => false,
/**
+ * Enables logging the PHP session ID with each log line
+ *
+ * This can be used for session-related debugging, e.g. to see when a session
+ * is ended or restarted.
+ *
+ * Defaults to ``false``.
+ */
+'log.sessionId' => false,
+
+/**
* This uses PHP.date formatting; see https://www.php.net/manual/en/function.date.php
*
* Defaults to ISO 8601 ``2005-08-15T15:52:01+00:00`` - see \DateTime::ATOM
diff --git a/lib/private/Log.php b/lib/private/Log.php
index 746e4d75b91..0787483e8f2 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -15,11 +15,13 @@ use OC\Log\ExceptionSerializer;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IRequest;
+use OCP\ISession;
use OCP\IUserSession;
use OCP\Log\BeforeMessageLoggedEvent;
use OCP\Log\IDataLogger;
use OCP\Log\IFileBased;
use OCP\Log\IWriter;
+use OCP\Session\Exceptions\SessionNotAvailableException;
use OCP\Support\CrashReport\IRegistry;
use Throwable;
use function array_merge;
@@ -170,6 +172,13 @@ class Log implements ILogger, IDataLogger {
if (!$hasBacktrace && $logBacktrace) {
$entry['backtrace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
+ if ($this->config->getValue('log.sessionId', false)) {
+ try {
+ $entry['sessionId'] = \OCP\Server::get(ISession::class)->getId();
+ } catch (SessionNotAvailableException) {
+ $entry['sessionId'] = false;
+ }
+ }
try {
if ($level >= $minLevel) {