]> source.dussan.org Git - nextcloud-server.git/commitdiff
catch exceptions that occur during logging 17206/head
authorRobin Appelman <robin@icewind.nl>
Thu, 19 Sep 2019 10:20:34 +0000 (12:20 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 19 Sep 2019 11:39:40 +0000 (13:39 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Log.php

index 4af833d778fb69862a702682bbd968dd187ae845..04148d549d6bc3ad53bbb3780d96bc5f53615e68 100644 (file)
@@ -214,24 +214,27 @@ class Log implements ILogger {
                }
                $message = strtr($message, $replace);
 
-               if ($level >= $minLevel) {
-                       $this->writeLog($app, $message, $level);
-
-                       if ($this->crashReporters !== null) {
-                               $messageContext = array_merge(
-                                       $context,
-                                       [
-                                               'level' => $level
-                                       ]
-                               );
-                               $this->crashReporters->delegateMessage($message, $messageContext);
-                       }
-               } else {
-                       if ($this->crashReporters !== null) {
-                               $this->crashReporters->delegateBreadcrumb($message, 'log', $context);
+               try {
+                       if ($level >= $minLevel) {
+                               $this->writeLog($app, $message, $level);
+
+                               if ($this->crashReporters !== null) {
+                                       $messageContext = array_merge(
+                                               $context,
+                                               [
+                                                       'level' => $level
+                                               ]
+                                       );
+                                       $this->crashReporters->delegateMessage($message, $messageContext);
+                               }
+                       } else {
+                               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) {
@@ -318,16 +321,20 @@ class Log implements ILogger {
 
                array_walk($context, [$this->normalizer, 'format']);
 
-               if ($level >= $minLevel) {
-                       if (!$this->logger instanceof IFileBased) {
-                               $data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);
+               try {
+                       if ($level >= $minLevel) {
+                               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;
-               if (!is_null($this->crashReporters)) {
-                       $this->crashReporters->delegateReport($exception, $context);
+                       $context['level'] = $level;
+                       if (!is_null($this->crashReporters)) {
+                               $this->crashReporters->delegateReport($exception, $context);
+                       }
+               } catch (\Throwable $e) {
+                       // make sure we dont hard crash if logging fails
                }
        }