mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
feat(log): add opt-in session ID logging
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
9b29df2dd5
commit
c9b316b028
2 changed files with 19 additions and 0 deletions
|
|
@ -1141,6 +1141,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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue