2018-11-10 22:03:03 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
|
|
class Debug
|
|
|
|
{
|
|
|
|
/**
|
2023-06-02 21:22:09 +03:00
|
|
|
* Convenience function for Configuration::getConfig('system', 'enable_debug_mode')
|
2022-07-01 16:10:30 +03:00
|
|
|
*/
|
2023-06-02 21:22:09 +03:00
|
|
|
public static function isEnabled(): bool
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2023-07-15 22:16:23 +03:00
|
|
|
$ip = $_SERVER['REMOTE_ADDR'] ?? 'x.y.z.1';
|
2023-06-02 21:22:09 +03:00
|
|
|
$enableDebugMode = Configuration::getConfig('system', 'enable_debug_mode');
|
|
|
|
$debugModeWhitelist = Configuration::getConfig('system', 'debug_mode_whitelist') ?: [];
|
|
|
|
if ($enableDebugMode && ($debugModeWhitelist === [] || in_array($ip, $debugModeWhitelist))) {
|
|
|
|
return true;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2023-06-02 21:22:09 +03:00
|
|
|
return false;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2024-08-07 04:15:43 +03:00
|
|
|
/**
|
|
|
|
* @deprecated Use $this->logger->debug()
|
|
|
|
*/
|
2022-09-08 20:07:57 +03:00
|
|
|
public static function log($message)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2022-10-16 18:55:43 +03:00
|
|
|
$e = new \Exception();
|
|
|
|
$trace = trace_from_exception($e);
|
|
|
|
// Drop the current frame
|
|
|
|
array_pop($trace);
|
|
|
|
$lastFrame = $trace[array_key_last($trace)];
|
|
|
|
$text = sprintf('%s(%s): %s', $lastFrame['file'], $lastFrame['line'], $message);
|
2023-09-21 23:05:55 +03:00
|
|
|
|
|
|
|
$logger = RssBridge::getLogger();
|
|
|
|
$logger->debug($text);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2018-11-10 22:03:03 +03:00
|
|
|
}
|