Skip to content
Snippets Groups Projects
Unverified Commit b2aec1d8 authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by GitHub
Browse files

Merge pull request #17206 from nextcloud/logger-catch-exceptions

catch exceptions that occur during logging
parents f7501939 2943c185
No related branches found
No related tags found
No related merge requests found
...@@ -214,24 +214,27 @@ class Log implements ILogger { ...@@ -214,24 +214,27 @@ class Log implements ILogger {
} }
$message = strtr($message, $replace); $message = strtr($message, $replace);
if ($level >= $minLevel) { try {
$this->writeLog($app, $message, $level); if ($level >= $minLevel) {
$this->writeLog($app, $message, $level);
if ($this->crashReporters !== null) {
$messageContext = array_merge( if ($this->crashReporters !== null) {
$context, $messageContext = array_merge(
[ $context,
'level' => $level [
] 'level' => $level
); ]
$this->crashReporters->delegateMessage($message, $messageContext); );
} $this->crashReporters->delegateMessage($message, $messageContext);
} else { }
if ($this->crashReporters !== null) { } else {
$this->crashReporters->delegateBreadcrumb($message, 'log', $context); if ($this->crashReporters !== null) {
$this->crashReporters->delegateBreadcrumb($message, 'log', $context);
}
} }
} catch (\Throwable $e) {
// make sure we dont hard crash if logging fails
} }
} }
private function getLogLevel($context) { private function getLogLevel($context) {
...@@ -318,16 +321,20 @@ class Log implements ILogger { ...@@ -318,16 +321,20 @@ class Log implements ILogger {
array_walk($context, [$this->normalizer, 'format']); array_walk($context, [$this->normalizer, 'format']);
if ($level >= $minLevel) { try {
if (!$this->logger instanceof IFileBased) { if ($level >= $minLevel) {
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR); if (!$this->logger instanceof IFileBased) {
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);
}
$this->writeLog($app, $data, $level);
} }
$this->writeLog($app, $data, $level);
}
$context['level'] = $level; $context['level'] = $level;
if (!is_null($this->crashReporters)) { if (!is_null($this->crashReporters)) {
$this->crashReporters->delegateReport($exception, $context); $this->crashReporters->delegateReport($exception, $context);
}
} catch (\Throwable $e) {
// make sure we dont hard crash if logging fails
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment