@@ -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
3131const 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
5146function 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 {
0 commit comments