Skip to content

Commit 9688264

Browse files
⚰️ More cleanup to reuse existing interface and remove stale const
1 parent 4c64a29 commit 9688264

2 files changed

Lines changed: 19 additions & 31 deletions

File tree

src/cloud/commands/logs.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ const SINCE_OPTIONS = [
1616
{ label: "1 day", value: "1d" },
1717
]
1818

19-
// Roughly matches fastapi-cloud-cli LOG_LEVEL_COLORS
20-
const LEVEL_COLORS: Record<string, string> = {
21-
debug: "#4488ff",
22-
info: "#00cccc",
23-
warning: "#ccaa00",
24-
warn: "#ccaa00",
25-
error: "#f14c4c",
26-
critical: "#cc66cc",
27-
fatal: "#cc66cc",
28-
default: "#888",
29-
}
19+
// Levels recognized when inferring a log's level from its message prefix.
20+
// Pipe colors for these live in the webview stylesheet, keyed on [data-level].
21+
const KNOWN_LEVELS = [
22+
"debug",
23+
"info",
24+
"warning",
25+
"warn",
26+
"error",
27+
"critical",
28+
"fatal",
29+
]
3030

3131
const FILTER_CHIPS = [
3232
{ level: "debug", label: "DEBUG" },
@@ -41,12 +41,7 @@ function formatTimestamp(ts: string): string {
4141
return Number.isNaN(d.getTime()) ? ts : `${d.toISOString().slice(0, 23)}Z`
4242
}
4343

44-
const MESSAGE_LEVEL_RE = new RegExp(
45-
`^\\s*(${Object.keys(LEVEL_COLORS)
46-
.filter((k) => k !== "default")
47-
.join("|")})\\b`,
48-
"i",
49-
)
44+
const MESSAGE_LEVEL_RE = new RegExp(`^\\s*(${KNOWN_LEVELS.join("|")})\\b`, "i")
5045

5146
function normalizeLevel(level: string, message?: string): string {
5247
// The streaming API returns "unknown" for new logs (Loki limitation) so try to infer from message prefix
@@ -60,13 +55,10 @@ function normalizeLevel(level: string, message?: string): string {
6055
return resolved
6156
}
6257

63-
export interface FormattedLogEntry {
64-
level: string
65-
timestamp: string
66-
message: string
67-
}
68-
69-
export function formatLogEntry(entry: AppLogEntry): FormattedLogEntry {
58+
// Returns the entry with its level normalized and timestamp formatted. Same
59+
// shape as the raw entry, but the webview builds the DOM node itself
60+
// (className/dataset/textContent), so no HTML escaping is required here.
61+
export function formatLogEntry(entry: AppLogEntry): AppLogEntry {
7062
const rawLevel = (entry.level ?? "info").toLowerCase()
7163
const level = normalizeLevel(rawLevel, entry.message)
7264
return {

src/cloud/ui/panel/webview.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// <reference lib="dom" />
22
/// <reference lib="dom.iterable" />
33

4+
import type { AppLogEntry } from "../../api"
5+
46
declare function acquireVsCodeApi(): { postMessage(msg: unknown): void }
57

68
const vscode = acquireVsCodeApi()
@@ -129,15 +131,9 @@ function setStreamingState(streaming: boolean, appLabel?: string): void {
129131
streaming && appLabel ? `Streaming logs for ${appLabel}...` : ""
130132
}
131133

132-
interface LogEntry {
133-
level: string
134-
timestamp: string
135-
message: string
136-
}
137-
138134
// Build the log line as a DOM node. The untrusted message is set as a text
139135
// node, so it is never parsed as HTML — no sanitization needed.
140-
function buildLogLine(entry: LogEntry): HTMLElement {
136+
function buildLogLine(entry: AppLogEntry): HTMLElement {
141137
const line = document.createElement("div")
142138
line.className = "log-line"
143139
line.dataset.level = entry.level

0 commit comments

Comments
 (0)