1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-07-30 21:30:14 +02:00

feat: improve logging and error handling (#2994)

* feat: improve logging and error handling

* trim absolute path from file name

* fix: suppress php errors from xml parsing

* fix: respect the error reporting level in the custom error handler

* feat: dont log error which is produced by bots

* ignore error about invalid bridge name

* upgrade bridge exception from warning to error

* remove remnants of using phps builin error handler

* move responsibility of printing php error from logger to error handler

* feat: include url in log record context

* fix: always include url in log record contect

Also ignore more non-interesting exceptions.

* more verbose httpexception

* fix

* fix
This commit is contained in:
Dag
2022-09-08 19:07:57 +02:00
committed by GitHub
parent 5578a735d9
commit 27b3d7c34e
11 changed files with 135 additions and 80 deletions

View File

@@ -14,17 +14,10 @@ final class RssBridge
try {
$this->run($request);
} catch (\Throwable $e) {
error_log($e);
$message = sprintf(
'Uncaught Exception %s: %s at %s line %s',
get_class($e),
$e->getMessage(),
trim_path_prefix($e->getFile()),
$e->getLine()
);
Logger::error('Exception in main', ['e' => $e]);
http_response_code(500);
print render('error.html.php', [
'message' => $message,
'message' => create_sane_exception_message($e),
'stacktrace' => create_sane_stacktrace($e),
]);
}
@@ -40,6 +33,17 @@ final class RssBridge
}
Configuration::loadConfiguration($customConfig, getenv());
set_error_handler(function ($code, $message, $file, $line) {
if ((error_reporting() & $code) === 0) {
return false;
}
$text = sprintf('%s at %s line %s', $message, trim_path_prefix($file), $line);
Logger::warning($text);
if (Debug::isEnabled()) {
print sprintf('<pre>%s</pre>', $text);
}
});
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
$authenticationMiddleware = new AuthenticationMiddleware();