gmdate('Y-m-d H:i:s'), 'level' => $level, 'message' => $message, 'context' => $context, ]; $logs[] = $entry; // Keep last MAX_ENTRIES if (count($logs) > self::MAX_ENTRIES) { $logs = array_slice($logs, -self::MAX_ENTRIES); } update_option(self::LOG_OPTION, $logs, false); } /** * Retrieves stored log entries. * * @return array */ /** * Detailed logging (the debug_mode setting) switches itself off 24 hours after it was turned on. * * @param int|null $now * @return bool */ public static function isDetailedLoggingOn(?int $now = null): bool { $now = $now ?? time(); $until = (int) Options::get(self::DETAILED_UNTIL, 0); if (!Options::get('debug_mode', false)) { if ($until !== 0) { Options::set(self::DETAILED_UNTIL, 0); } return false; } if ($until === 0) { Options::set(self::DETAILED_UNTIL, $now + self::DETAILED_SECONDS); return true; } if ($now >= $until) { Options::set('debug_mode', false); Options::set(self::DETAILED_UNTIL, 0); return false; } return true; } public static function getLogs(): array { $logs = get_option(self::LOG_OPTION, []); return is_array($logs) ? $logs : []; } /** * Clears all log entries. */ public static function clear(): void { delete_option(self::LOG_OPTION); } }