From 94953dc039119018e03d481d00ed831176d6e3a1 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Tue, 28 Mar 2023 21:20:08 +0100 Subject: [PATCH] WIP: Replace more ILogger method calls This commit replaces more ILogger method calls with `Psr\Log\LoggerInterface` as we gradually move away from the custom ILogger. Signed-off-by: fenn-cs --- index.php | 21 ++++++++++++++++----- lib/private/Server.php | 7 +++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 7b62f17e5bd58..470045296fe62 100644 --- a/index.php +++ b/index.php @@ -35,7 +35,9 @@ OC::handleRequest(); } catch (\OC\ServiceUnavailableException $ex) { - \OC::$server->getLogger()->logException($ex, ['app' => 'index']); + \OC::$server->getPsrLogger()->error($ex->getMessage(), [ + 'exception' => $ex, + ]); //show the user a detailed error page OC_Template::printExceptionErrorPage($ex, 503); @@ -44,8 +46,12 @@ OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503); } catch (Exception $ex2) { try { - \OC::$server->getLogger()->logException($ex, ['app' => 'index']); - \OC::$server->getLogger()->logException($ex2, ['app' => 'index']); + \OC::$server->getPsrLogger()->error($ex->getMessage(), [ + 'exception' => $ex, + ]); + \OC::$server->getPsrLogger()->error($ex2->getMessage(), [ + 'exception' => $ex2, + ]); } catch (Throwable $e) { // no way to log it properly - but to avoid a white page of death we try harder and ignore this one here } @@ -68,13 +74,17 @@ } OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401); } catch (Exception $ex) { - \OC::$server->getLogger()->logException($ex, ['app' => 'index']); + \OC::$server->getPsrLogger()->error($ex->getMessage(), [ + 'exception' => $ex, + ]); //show the user a detailed error page OC_Template::printExceptionErrorPage($ex, 500); } catch (Error $ex) { try { - \OC::$server->getLogger()->logException($ex, ['app' => 'index']); + \OC::$server->getPsrLogger()->error($ex->getMessage(), [ + 'exception' => $ex, + ]); } catch (Error $e) { http_response_code(500); header('Content-Type: text/plain; charset=utf-8'); @@ -83,6 +93,7 @@ print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); print("More details can be found in the webserver log.\n"); + throw $ex; } OC_Template::printExceptionErrorPage($ex, 500); diff --git a/lib/private/Server.php b/lib/private/Server.php index f1e9617088662..d6342d832b4ca 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1834,6 +1834,13 @@ public function getLogger() { return $this->get(ILogger::class); } + public function getPsrLogger(): LoggerInterface { + $logFactory = $this->get(LogFactory::class); + $default = $this->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log'; + $logFile = $this->getConfig()->getAppValue('admin_audit', 'logfile', $default); + return $logFactory->getCustomPsrLogger($logFile); + } + /** * @return ILogFactory * @throws \OCP\AppFramework\QueryException