Merge pull request #9147 from nextcloud/log-previous-exception

log previous exception
This commit is contained in:
Morris Jobke 2018-04-11 15:11:46 +02:00 committed by GitHub
commit b7009753b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 12 deletions

View File

@ -353,6 +353,27 @@ class Log implements ILogger {
return $args; return $args;
} }
private function serializeException(\Throwable $exception) {
$data = [
'Exception' => get_class($exception),
'Message' => $exception->getMessage(),
'Code' => $exception->getCode(),
'Trace' => $this->filterTrace($exception->getTrace()),
'File' => $exception->getFile(),
'Line' => $exception->getLine(),
];
if ($exception instanceof HintException) {
$data['Hint'] = $exception->getHint();
}
if ($exception->getPrevious()) {
$data['Previous'] = $this->serializeException($exception->getPrevious());
}
return $data;
}
/** /**
* Logs an exception very detailed * Logs an exception very detailed
* *
@ -365,18 +386,8 @@ class Log implements ILogger {
$app = $context['app'] ?? 'no app in context'; $app = $context['app'] ?? 'no app in context';
$level = $context['level'] ?? Util::ERROR; $level = $context['level'] ?? Util::ERROR;
$data = [ $data = $this->serializeException($exception);
'CustomMessage' => $context['message'] ?? '--', $data['CustomMessage'] = $context['message'] ?? '--';
'Exception' => get_class($exception),
'Message' => $exception->getMessage(),
'Code' => $exception->getCode(),
'Trace' => $this->filterTrace($exception->getTrace()),
'File' => $exception->getFile(),
'Line' => $exception->getLine(),
];
if ($exception instanceof HintException) {
$data['Hint'] = $exception->getHint();
}
$minLevel = $this->getLogLevel($context); $minLevel = $this->getLogLevel($context);