diff options
author | Andreas Gohr <andi@splitbrain.org> | 2022-08-14 17:07:41 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2022-08-14 17:07:41 +0200 |
commit | 25edeeca14acaa318ea8f0009bd3a8f20921558f (patch) | |
tree | b4e0ada0d5e30b702b7818d7e5c158a8b576069b | |
parent | aa726f38a40544f44d4b097135b01548b4ce6229 (diff) | |
download | dokuwiki-25edeeca14acaa318ea8f0009bd3a8f20921558f.tar.gz dokuwiki-25edeeca14acaa318ea8f0009bd3a8f20921558f.zip |
log deprecation messages independent from allowdebug
Only the logging configuration should influnece if deprecation messages
are to be logged. By default they should be logged.
-rw-r--r-- | inc/Debug/DebugHelper.php | 73 | ||||
-rw-r--r-- | inc/Logger.php | 12 |
2 files changed, 49 insertions, 36 deletions
diff --git a/inc/Debug/DebugHelper.php b/inc/Debug/DebugHelper.php index 6bdd573e7..a3f7a4de6 100644 --- a/inc/Debug/DebugHelper.php +++ b/inc/Debug/DebugHelper.php @@ -12,25 +12,37 @@ class DebugHelper const INFO_DEPRECATION_LOG_EVENT = 'INFO_DEPRECATION_LOG'; /** - * Log accesses to deprecated fucntions to the debug log + * Check if deprecation messages shall be handled * - * @param string $alternative (optional) The function or method that should be used instead - * @param int $callerOffset (optional) How far the deprecated method is removed from this one - * @param string $thing (optional) The deprecated thing, defaults to the calling method - * @triggers \dokuwiki\Debug::INFO_DEPRECATION_LOG_EVENT + * This is either because its logging is not disabled or a deprecation handler was registered + * + * @return bool */ - public static function dbgDeprecatedFunction($alternative = '', $callerOffset = 1, $thing = '') + public static function isEnabled() { - global $conf; /** @var EventHandler $EVENT_HANDLER */ global $EVENT_HANDLER; if ( - !$conf['allowdebug'] && + !Logger::getInstance(Logger::LOG_DEPRECATED)->isLogging() && ($EVENT_HANDLER === null || !$EVENT_HANDLER->hasHandlerForEvent('INFO_DEPRECATION_LOG')) - ){ + ) { // avoid any work if no one cares - return; + return false; } + return true; + } + + /** + * Log accesses to deprecated fucntions to the debug log + * + * @param string $alternative (optional) The function or method that should be used instead + * @param int $callerOffset (optional) How far the deprecated method is removed from this one + * @param string $thing (optional) The deprecated thing, defaults to the calling method + * @triggers \dokuwiki\Debug::INFO_DEPRECATION_LOG_EVENT + */ + public static function dbgDeprecatedFunction($alternative = '', $callerOffset = 1, $thing = '') + { + if (!self::isEnabled()) return; $backtrace = debug_backtrace(); for ($i = 0; $i < $callerOffset; $i += 1) { @@ -63,19 +75,14 @@ class DebugHelper * This is usually called withing a magic getter or setter. * For logging deprecated functions or methods see dbgDeprecatedFunction() * - * @param string $class The class with the deprecated property + * @param string $class The class with the deprecated property * @param string $propertyName The name of the deprecated property * * @triggers \dokuwiki\Debug::INFO_DEPRECATION_LOG_EVENT */ public static function dbgDeprecatedProperty($class, $propertyName) { - global $conf; - global $EVENT_HANDLER; - if (!$conf['allowdebug'] && !$EVENT_HANDLER->hasHandlerForEvent(self::INFO_DEPRECATION_LOG_EVENT)) { - // avoid any work if no one cares - return; - } + if (!self::isEnabled()) return; $backtrace = debug_backtrace(); array_shift($backtrace); @@ -102,8 +109,8 @@ class DebugHelper * @param string $deprecatedThing * @param string $caller * @param string $file - * @param int $line - * @param int $callerOffset How many lines should be removed from the beginning of the backtrace + * @param int $line + * @param int $callerOffset How many lines should be removed from the beginning of the backtrace */ public static function dbgCustomDeprecationEvent( $alternative, @@ -112,14 +119,9 @@ class DebugHelper $file, $line, $callerOffset = 1 - ) { - global $conf; - /** @var EventHandler $EVENT_HANDLER */ - global $EVENT_HANDLER; - if (!$conf['allowdebug'] && !$EVENT_HANDLER->hasHandlerForEvent(self::INFO_DEPRECATION_LOG_EVENT)) { - // avoid any work if no one cares - return; - } + ) + { + if (!self::isEnabled()) return; $backtrace = array_slice(debug_backtrace(), $callerOffset); @@ -135,21 +137,22 @@ class DebugHelper } /** - * @param array $backtrace + * @param array $backtrace * @param string $alternative * @param string $deprecatedThing * @param string $caller * @param string $file - * @param int $line + * @param int $line */ private static function triggerDeprecationEvent( array $backtrace, - $alternative, - $deprecatedThing, - $caller, - $file, - $line - ) { + $alternative, + $deprecatedThing, + $caller, + $file, + $line + ) + { $data = [ 'trace' => $backtrace, 'alternative' => $alternative, diff --git a/inc/Logger.php b/inc/Logger.php index e48636c06..0877f20a6 100644 --- a/inc/Logger.php +++ b/inc/Logger.php @@ -147,6 +147,16 @@ class Logger } /** + * Is this logging instace actually logging? + * + * @return bool + */ + public function isLogging() + { + return $this->isLogging; + } + + /** * Formats the given data as loglines * * @param array $data Event data from LOGGER_DATA_FORMAT @@ -193,7 +203,7 @@ class Logger { global $conf; - if($date !== null && !is_numeric($date)) { + if ($date !== null && !is_numeric($date)) { $date = strtotime($date); } if (!$date) $date = time(); |