From ea917512178598ddfb2f732d4384583c2a1be6e7 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sun, 12 Oct 2025 14:51:07 +0200 Subject: [PATCH] Update system-logs.tsx --- AppImage/components/system-logs.tsx | 101 +++++++++++++++------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/AppImage/components/system-logs.tsx b/AppImage/components/system-logs.tsx index 80f873a..a66b8c2 100644 --- a/AppImage/components/system-logs.tsx +++ b/AppImage/components/system-logs.tsx @@ -96,11 +96,6 @@ interface CombinedLogEntry { } export function SystemLogs() { - console.log("[v0] ========================================") - console.log("[v0] SystemLogs v47 - TABS SHOULD BE MERGED") - console.log("[v0] Expected tabs: Logs & Events, Backups, Notifications") - console.log("[v0] ========================================") - const [logs, setLogs] = useState([]) const [backups, setBackups] = useState([]) const [events, setEvents] = useState([]) @@ -291,43 +286,65 @@ export function SystemLogs() { } } - const handleDownloadLogs = async (type = "system") => { + const handleDownloadLogs = async () => { try { - const hours = 48 - - // This part seems to be intended for system logs specifically, and might not apply directly to combined logs/events. - // For now, we'll keep it as is, assuming it's for a specific download scenario. - // If the intent is to download combined logs/events, this function would need modification. - - let url = getApiUrl(`/api/logs/download?type=${type}&hours=${hours}`) - - // Apply filters if any are active + // Generate filename based on active filters + const filters = [] + if (dateFilter !== "now") { + const days = dateFilter === "custom" ? customDays : dateFilter + filters.push(`${days}days`) + } if (levelFilter !== "all") { - url += `&level=${levelFilter}` + filters.push(levelFilter) } if (serviceFilter !== "all") { - url += `&service=${serviceFilter}` + filters.push(serviceFilter) + } + if (searchTerm) { + filters.push("searched") } - if (dateFilter !== "now") { - const daysAgo = dateFilter === "custom" ? Number.parseInt(customDays) : Number.parseInt(dateFilter) - url += `&since_days=${daysAgo}` - } + const filename = `proxmox_logs_${filters.length > 0 ? filters.join("_") + "_" : ""}${new Date().toISOString().split("T")[0]}.txt` - const response = await fetch(url) - if (response.ok) { - const blob = await response.blob() - const downloadUrl = window.URL.createObjectURL(blob) - const a = document.createElement("a") - a.href = downloadUrl - a.download = `proxmox_${type}_${hours}h.log` - document.body.appendChild(a) - a.click() - window.URL.revokeObjectURL(downloadUrl) - document.body.removeChild(a) - } + // Generate log content + const logContent = [ + `Proxmox System Logs & Events Export`, + `Generated: ${new Date().toISOString()}`, + `Total Entries: ${filteredCombinedLogs.length.toLocaleString()}`, + ``, + `Filters Applied:`, + `- Date Range: ${dateFilter === "now" ? "Current logs" : dateFilter === "custom" ? `${customDays} days ago` : `${dateFilter} days ago`}`, + `- Level: ${levelFilter === "all" ? "All Levels" : levelFilter}`, + `- Service: ${serviceFilter === "all" ? "All Services" : serviceFilter}`, + `- Search: ${searchTerm || "None"}`, + ``, + `${"=".repeat(80)}`, + ``, + ...filteredCombinedLogs.map((log) => { + const lines = [ + `[${log.timestamp}] ${log.level.toUpperCase()} - ${log.service}${log.isEvent ? " [EVENT]" : ""}`, + `Message: ${log.message}`, + `Source: ${log.source}`, + ] + if (log.pid) lines.push(`PID: ${log.pid}`) + if (log.hostname) lines.push(`Hostname: ${log.hostname}`) + lines.push(`${"-".repeat(80)}`) + return lines.join("\n") + }), + ].join("\n") + + // Create and download blob + const blob = new Blob([logContent], { type: "text/plain" }) + const url = window.URL.createObjectURL(blob) + const a = document.createElement("a") + a.href = url + a.download = filename + document.body.appendChild(a) + a.click() + window.URL.revokeObjectURL(url) + document.body.removeChild(a) } catch (err) { - console.error("[v0] Error downloading logs:", err) + console.error("Error exporting logs:", err) } } @@ -568,8 +585,6 @@ export function SystemLogs() { return (
- {console.log("[v0] SystemLogs component rendered - Tabs should be: Logs & Events, Backups, Notifications")} - {loading && (logs.length > 0 || events.length > 0) && (
@@ -588,7 +603,7 @@ export function SystemLogs() { -
{filteredCombinedLogs.length}
+
{filteredCombinedLogs.length.toLocaleString()}

Filtered

@@ -599,7 +614,7 @@ export function SystemLogs() { -
{logCounts.error}
+
{logCounts.error.toLocaleString()}

Requires attention

@@ -610,7 +625,7 @@ export function SystemLogs() { -
{logCounts.warning}
+
{logCounts.warning.toLocaleString()}

Monitor closely

@@ -621,7 +636,7 @@ export function SystemLogs() { -
{backupStats.total}
+
{backupStats.total.toLocaleString()}

{formatBytes(backupStats.totalSize)}

@@ -776,11 +791,7 @@ export function SystemLogs() { -