2022-09-08 20:07:57 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class Logger
|
|
|
|
{
|
2022-10-16 18:55:43 +03:00
|
|
|
public static function debug(string $message, array $context = [])
|
|
|
|
{
|
2022-10-29 11:27:02 +03:00
|
|
|
if (Debug::isEnabled()) {
|
|
|
|
self::log('DEBUG', $message, $context);
|
|
|
|
}
|
2022-10-16 18:55:43 +03:00
|
|
|
}
|
|
|
|
|
2022-09-08 20:07:57 +03:00
|
|
|
public static function info(string $message, array $context = []): void
|
|
|
|
{
|
|
|
|
self::log('INFO', $message, $context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function warning(string $message, array $context = []): void
|
|
|
|
{
|
|
|
|
self::log('WARNING', $message, $context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function error(string $message, array $context = []): void
|
|
|
|
{
|
|
|
|
self::log('ERROR', $message, $context);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function log(string $level, string $message, array $context = []): void
|
|
|
|
{
|
|
|
|
if (isset($context['e'])) {
|
|
|
|
$context['message'] = create_sane_exception_message($context['e']);
|
|
|
|
$context['code'] = $context['e']->getCode();
|
|
|
|
$context['url'] = get_current_url();
|
2022-10-16 18:55:43 +03:00
|
|
|
$context['trace'] = trace_to_call_points(trace_from_exception($context['e']));
|
2022-09-08 20:07:57 +03:00
|
|
|
unset($context['e']);
|
2022-10-16 18:55:43 +03:00
|
|
|
// Don't log these records
|
2022-09-08 20:07:57 +03:00
|
|
|
$ignoredExceptions = [
|
2022-10-16 18:55:43 +03:00
|
|
|
'Exception Exception: You must specify a format',
|
|
|
|
'Exception InvalidArgumentException: Format name invalid',
|
|
|
|
'Exception InvalidArgumentException: Unknown format given',
|
|
|
|
'Exception InvalidArgumentException: Bridge name invalid',
|
2022-10-26 01:47:45 +03:00
|
|
|
'Exception Exception: Invalid action',
|
2022-09-09 21:18:50 +03:00
|
|
|
'Exception Exception: twitter: No results for this query',
|
2022-10-26 01:47:45 +03:00
|
|
|
// telegram
|
|
|
|
'Exception Exception: Unable to find channel. The channel is non-existing or non-public',
|
|
|
|
// fb
|
|
|
|
'Exception Exception: This group is not public! RSS-Bridge only supports public groups!',
|
2022-09-08 20:07:57 +03:00
|
|
|
];
|
|
|
|
foreach ($ignoredExceptions as $ignoredException) {
|
|
|
|
if (str_starts_with($context['message'], $ignoredException)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$text = sprintf(
|
|
|
|
"[%s] rssbridge.%s %s %s\n",
|
|
|
|
now()->format('Y-m-d H:i:s'),
|
|
|
|
$level,
|
|
|
|
$message,
|
|
|
|
$context ? Json::encode($context) : ''
|
|
|
|
);
|
|
|
|
error_log($text);
|
|
|
|
}
|
|
|
|
}
|