Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function logException(\Throwable $exception, array $context = []) {
$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'] ?? '--';

Expand Down
24 changes: 21 additions & 3 deletions lib/private/Log/ExceptionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OC\HintException;
use OC\Security\IdentityProof\Key;
use OC\Setup;
use OC\SystemConfig;

class ExceptionSerializer {
public const methodsWithSensitiveParameters = [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -162,11 +170,21 @@ private function encodeArg($arg) {
$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) {
Expand Down