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

Improve logging and error handling (#3059)

* refactor: logging and errror handling
This commit is contained in:
Dag
2022-10-16 17:55:43 +02:00
committed by GitHub
parent e21394d2d3
commit ffbc107687
13 changed files with 143 additions and 93 deletions

View File

@@ -4,6 +4,11 @@ declare(strict_types=1);
final class Logger
{
public static function debug(string $message, array $context = [])
{
self::log('DEBUG', $message, $context);
}
public static function info(string $message, array $context = []): void
{
self::log('INFO', $message, $context);
@@ -23,22 +28,20 @@ final class Logger
{
if (isset($context['e'])) {
$context['message'] = create_sane_exception_message($context['e']);
$context['file'] = trim_path_prefix($context['e']->getFile());
$context['line'] = $context['e']->getLine();
$context['code'] = $context['e']->getCode();
$context['url'] = get_current_url();
$context['trace'] = create_sane_stacktrace($context['e']);
$context['trace'] = trace_to_call_points(trace_from_exception($context['e']));
unset($context['e']);
// Don't log these records
$ignoredExceptions = [
'Exception Exception: You must specify a format!',
'Exception InvalidArgumentException: Format name invalid!',
'Exception InvalidArgumentException: Unknown format given!',
'Exception InvalidArgumentException: Bridge name invalid!',
'Exception Exception: You must specify a format',
'Exception InvalidArgumentException: Format name invalid',
'Exception InvalidArgumentException: Unknown format given',
'Exception InvalidArgumentException: Bridge name invalid',
'Exception Exception: twitter: No results for this query',
];
foreach ($ignoredExceptions as $ignoredException) {
if (str_starts_with($context['message'], $ignoredException)) {
// Don't log this record because it's usually a bot
return;
}
}