1) { // Do not include the call to Debug::log
$debugmessage .= ' '
. $caller['class']
. $caller['type']
. $caller['function']
. '()';
}
$debugmessage .= ']';
// Stop at the first caller that isn't part of simplehtmldom
if (!isset($caller['class']) || strpos($caller['class'], 'simplehtmldom\\') !== 0) {
break;
}
}
$output = '[DEBUG] ' . trim($debugmessage) . ' "' . $message . '"';
if (is_null(self::$debugHandler)) {
//error_log($output);
} else {
call_user_func_array(self::$debugHandler, array($output));
}
}
/**
* Adds a debug message to error_log if debug mode is enabled. Does nothing
* if debug mode is disabled.
*
* @param string $text The message to add to error_log
*/
public static function log($message)
{
if (!self::isEnabled()) return;
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
self::log_trace($message, $backtrace);
}
/**
* Adds a debug message to error_log if debug mode is enabled. Does nothing
* if debug mode is disabled. Each message is logged only once.
*
* @param string $text The message to add to error_log
*/
public static function log_once($message)
{
if (!self::isEnabled()) return;
// Keep track of caller (file & line)
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
if (in_array($backtrace[0], self::$callerLock, true)) return;
self::$callerLock[] = $backtrace[0];
self::log_trace($message, $backtrace);
}
}