diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-12-29 11:38:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-29 11:38:27 +0100 |
commit | c9fcf5f6b152e64c911578f687d70c4c5a03d1b2 (patch) | |
tree | 0183a8bb965914530ec73465d7bbfd1be0ed5dc7 /lib | |
parent | 35aa34a1fd5e10a1edfd8afd50dc42ec613c793a (diff) | |
parent | 179de95f8108fde9271637fab45fe648ff25771e (diff) | |
download | nextcloud-server-c9fcf5f6b152e64c911578f687d70c4c5a03d1b2.tar.gz nextcloud-server-c9fcf5f6b152e64c911578f687d70c4c5a03d1b2.zip |
Merge pull request #24874 from nextcloud/enh/exception_logging
Avoid huge exception argument logging
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Log.php | 2 | ||||
-rw-r--r-- | lib/private/Log/ExceptionSerializer.php | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index 83b92ecd1ab..db86aa8bfe3 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -314,7 +314,7 @@ class Log implements ILogger, IDataLogger { $app = $context['app'] ?? 'no app in context'; $level = $context['level'] ?? ILogger::ERROR; - $serializer = new ExceptionSerializer(); + $serializer = new ExceptionSerializer($this->config); $data = $serializer->serializeException($exception); $data['CustomMessage'] = $context['message'] ?? '--'; diff --git a/lib/private/Log/ExceptionSerializer.php b/lib/private/Log/ExceptionSerializer.php index 0cb68f08914..ae3e6ba100d 100644 --- a/lib/private/Log/ExceptionSerializer.php +++ b/lib/private/Log/ExceptionSerializer.php @@ -33,6 +33,7 @@ use OC\Core\Controller\SetupController; use OC\HintException; use OC\Security\IdentityProof\Key; use OC\Setup; +use OC\SystemConfig; class ExceptionSerializer { public const methodsWithSensitiveParameters = [ @@ -92,6 +93,13 @@ class ExceptionSerializer { 'imagecreatefromstring', ]; + /** @var SystemConfig */ + private $systemConfig; + + public function __construct(SystemConfig $systemConfig) { + $this->systemConfig = $systemConfig; + } + public const methodsWithSensitiveParametersByClass = [ SetupController::class => [ 'run', @@ -163,11 +171,21 @@ class ExceptionSerializer { $data = get_object_vars($arg); $data['__class__'] = get_class($arg); return array_map([$this, 'encodeArg'], $data); - } elseif (is_array($arg)) { + } + + if (is_array($arg)) { + // Only log the first 5 elements of an array unless we are on debug + if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) { + $elemCount = count($arg); + if ($elemCount > 5) { + $arg = array_slice($arg, 0, 5); + $arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries'; + } + } return array_map([$this, 'encodeArg'], $arg); - } else { - return $arg; } + + return $arg; } public function serializeException(\Throwable $exception) { |