Merge pull request #24876 from nextcloud/backport/24874/stable20
[stable20] Avoid huge exception argument logging
This commit is contained in:
commit
f16746e902
|
@ -315,7 +315,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'] ?? '--';
|
||||
|
||||
|
|
|
@ -32,6 +32,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 = [
|
||||
|
@ -91,6 +92,13 @@ class ExceptionSerializer {
|
|||
'imagecreatefromstring',
|
||||
];
|
||||
|
||||
/** @var SystemConfig */
|
||||
private $systemConfig;
|
||||
|
||||
public function __construct(SystemConfig $systemConfig) {
|
||||
$this->systemConfig = $systemConfig;
|
||||
}
|
||||
|
||||
public const methodsWithSensitiveParametersByClass = [
|
||||
SetupController::class => [
|
||||
'run',
|
||||
|
@ -162,11 +170,21 @@ class ExceptionSerializer {
|
|||
$data = get_object_vars($arg);
|
||||
$data['__class__'] = get_class($arg);
|
||||
return array_map([$this, 'encodeArg'], $data);
|
||||
} elseif (is_array($arg)) {
|
||||
return array_map([$this, 'encodeArg'], $arg);
|
||||
} else {
|
||||
return $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);
|
||||
}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
public function serializeException(\Throwable $exception) {
|
||||
|
|
Loading…
Reference in New Issue