|
32 | 32 | use OC\HintException; |
33 | 33 | use OC\Security\IdentityProof\Key; |
34 | 34 | use OC\Setup; |
| 35 | +use OC\SystemConfig; |
35 | 36 |
|
36 | 37 | class ExceptionSerializer { |
37 | 38 | public const methodsWithSensitiveParameters = [ |
@@ -91,6 +92,13 @@ class ExceptionSerializer { |
91 | 92 | 'imagecreatefromstring', |
92 | 93 | ]; |
93 | 94 |
|
| 95 | + /** @var SystemConfig */ |
| 96 | + private $systemConfig; |
| 97 | + |
| 98 | + public function __construct(SystemConfig $systemConfig) { |
| 99 | + $this->systemConfig = $systemConfig; |
| 100 | + } |
| 101 | + |
94 | 102 | public const methodsWithSensitiveParametersByClass = [ |
95 | 103 | SetupController::class => [ |
96 | 104 | 'run', |
@@ -162,11 +170,21 @@ private function encodeArg($arg) { |
162 | 170 | $data = get_object_vars($arg); |
163 | 171 | $data['__class__'] = get_class($arg); |
164 | 172 | return array_map([$this, 'encodeArg'], $data); |
165 | | - } elseif (is_array($arg)) { |
| 173 | + } |
| 174 | + |
| 175 | + if (is_array($arg)) { |
| 176 | + // Only log the first 5 elements of an array unless we are on debug |
| 177 | + if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) { |
| 178 | + $elemCount = count($arg); |
| 179 | + if ($elemCount > 5) { |
| 180 | + $arg = array_slice($arg, 0, 5); |
| 181 | + $arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries'; |
| 182 | + } |
| 183 | + } |
166 | 184 | return array_map([$this, 'encodeArg'], $arg); |
167 | | - } else { |
168 | | - return $arg; |
169 | 185 | } |
| 186 | + |
| 187 | + return $arg; |
170 | 188 | } |
171 | 189 |
|
172 | 190 | public function serializeException(\Throwable $exception) { |
|
0 commit comments