Skip to content

Commit

Permalink
Replace ILogger method calls index.php
Browse files Browse the repository at this point in the history
This commit replaces more ILogger method calls with
 `Psr\Log\LoggerInterface` as we gradually move away from the
 custom ILogger.

This commit aslo, sets the customPsrLogger to not depend on the
 database to `logfile` config value.

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
Fenn-CS committed May 22, 2023
1 parent 96f0118 commit bb2c2bb
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
*
*/
require_once __DIR__ . '/lib/versioncheck.php';
use Psr\Log\LoggerInterface;

try {
require_once __DIR__ . '/lib/base.php';

OC::handleRequest();
} catch (\OC\ServiceUnavailableException $ex) {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);

//show the user a detailed error page
OC_Template::printExceptionErrorPage($ex, 503);
Expand All @@ -44,8 +48,14 @@
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->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [
'app' => 'index',
'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
}
Expand All @@ -68,13 +78,19 @@
}
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
} catch (Exception $ex) {
\OC::$server->getLogger()->logException($ex, ['app' => 'index']);
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'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->get(LoggerInterface::class)->error($ex->getMessage(), [
'app' => 'index',
'exception' => $ex,
]);
} catch (Error $e) {
http_response_code(500);
header('Content-Type: text/plain; charset=utf-8');
Expand Down

0 comments on commit bb2c2bb

Please sign in to comment.