New group logging
This commit is contained in:
1 parent
400837b41a
commit
cded4a0200
14 files changed
+324
-75
No files matched your search
@@ -169,13 +169,40 @@ export class LogExplorer implements vscode.Disposable {
|
||||
} finally { this.busy = false; }
|
||||
}
|
||||
private publish() {
|
||||
const entries = [...this.entries.values()].sort((a, b) => a.time - b.time);
|
||||
const entries = [...this.entries.values()].sort((a, b) => {
|
||||
const time = a.time - b.time;
|
||||
if (time) { return time; }
|
||||
// Include raw app.log() lines written in the same second as initialization markers.
|
||||
const priority = (entry: LogEntry) => /Initialization (?:started|completed|failed)/.test(entry.message)
|
||||
? (entry.message.includes('started') ? -1 : 1) : 0;
|
||||
return priority(a) - priority(b);
|
||||
});
|
||||
// Legacy errors duplicated across main/error logs are merged only on exact match.
|
||||
const seen = new Set<string>();
|
||||
const unique = entries.filter(e => {
|
||||
const key = e.trace_id ? e.event_id : `${e.timestamp}|${e.app}|${e.level}|${e.message}`;
|
||||
if (seen.has(key)) { return false; } seen.add(key); return true;
|
||||
});
|
||||
// Direct app.log() calls have no LoggerInterface tag. Infer their initialization
|
||||
// group while an explicit per-app initialize() scope is open.
|
||||
const activeInitialization = new Map<string, string>();
|
||||
for (const entry of unique) {
|
||||
const marker = entry.message.match(/Initialization (started|completed|failed) \[group=initialization:([a-f0-9]{12})\]/i);
|
||||
if (marker?.[1] === 'started') { activeInitialization.set(entry.app, marker[2]); }
|
||||
const activeId = activeInitialization.get(entry.app);
|
||||
if (activeId && !entry.group_id) {
|
||||
entry.group_id = activeId;
|
||||
entry.group_kind = 'initialization';
|
||||
entry.initialization_id = activeId;
|
||||
entry.phase = 'initialization';
|
||||
entry.group_inferred = true;
|
||||
}
|
||||
if (entry.group_kind === 'initialization') {
|
||||
entry.initialization_id = entry.initialization_id || entry.group_id;
|
||||
entry.phase = 'initialization';
|
||||
}
|
||||
if (marker && (marker[1] === 'completed' || marker[1] === 'failed')) { activeInitialization.delete(entry.app); }
|
||||
}
|
||||
const zone = vscode.workspace.getConfiguration('appdaemon').get<string>('logTimezone', 'Europe/Berlin');
|
||||
this.activeWebview?.postMessage({ type: 'entries', entries: unique, warnings: [...this.warnings], limit: 10000, timezone: zone });
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ export interface LogEntry {
|
||||
entity?: string; values?: Record<string, unknown>;
|
||||
source?: { path: string; line: number };
|
||||
initialization_id?: string; phase?: string; status?: string;
|
||||
group_id?: string; group_kind?: string; group_inferred?: boolean;
|
||||
file?: string; raw?: string; time: number; trace_id?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
@@ -38,8 +39,11 @@ export function parseLine(line: string, file: string, offset: number, zone = 'Eu
|
||||
const m = line.match(/^(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?)\s+(DEBUG|INFO|WARNING|ERROR|CRITICAL)\s+([^:]+):\s?(.*)$/);
|
||||
if (!m) { return undefined; }
|
||||
const init = m[4].match(/\[init=([\w-]+)\]/);
|
||||
const group = m[4].match(/\[group=(initialization|smartcondition|value_selector):([a-f0-9]{12})\]/i);
|
||||
const id = m[4].match(/\[event=([\w-]+) trace=([\w-]+)\]/);
|
||||
return { event_id: id?.[1] || `${file}:${offset}`, trace_id: id?.[2], initialization_id: init?.[1], phase: init ? 'initialization' : undefined, timestamp: m[1], time: rawTime(m[1], zone), app: m[3].trim(), level: m[2], message: m[4], kind: 'log', cause_ids: [], file, raw: line };
|
||||
const groupKind = group?.[1]?.toLowerCase();
|
||||
const initializationId = groupKind === 'initialization' ? group?.[2] : init?.[1];
|
||||
return { event_id: id?.[1] || `${file}:${offset}`, trace_id: id?.[2], initialization_id: initializationId, phase: initializationId ? 'initialization' : undefined, group_id: group?.[2], group_kind: groupKind, timestamp: m[1], time: rawTime(m[1], zone), app: m[3].trim(), level: m[2], message: m[4], kind: 'log', cause_ids: [], file, raw: line };
|
||||
}
|
||||
|
||||
/** Preserve valid UTF-8 spans, including files containing mixed legacy bytes. */
|
||||
|
||||
Reference in new issue
Block a user