Simplify the log grouping logic
This commit is contained in:
1 parent
f57e23d76a
commit
3aa0120e3d
10 files changed
+82
-84
No files matched your search
@@ -26,7 +26,7 @@
|
||||
&& (level === 'all' || normalLevel(e) === level)
|
||||
&& `${e.app} ${e.entity || ''} ${e.message}`.toLowerCase().includes(q));
|
||||
}
|
||||
const cleanMessage = e => e.message.replace(/ \[event=[\w-]+ trace=[\w-]+\]/g, '').replace(/ \[init=[\w-]+\]/g, '').replace(/ \[group=(?:initialization|smartcondition|value_selector):[a-f0-9]{12}\]/gi, '');
|
||||
const cleanMessage = e => e.message.replace(/ \[event=[\w-]+ trace=[\w-]+\]/g, '').replace(/ \[init=[^\]]+\]/g, '').replace(/ \[group=[^\]]+:[a-f0-9]{12}\]/gi, '');
|
||||
const formatTime = (entry, includeYear = false) => {
|
||||
if (!Number.isFinite(entry.time)) return entry.timestamp;
|
||||
try {
|
||||
@@ -68,13 +68,12 @@
|
||||
});
|
||||
return container;
|
||||
}
|
||||
function blockTitle(items, groupKey) {
|
||||
function blockTitle(items) {
|
||||
const first = items[0];
|
||||
const kind = groupKey?.startsWith('initialization:') || first.initialization_id ? 'initialization' : items.find(entry => entry.group_kind)?.group_kind;
|
||||
const names = { initialization: 'Initialization', smartcondition: 'Smart condition', value_selector: 'Value selector' };
|
||||
const name = names[kind] || (items.length > 1 || first.trace_id ? 'Event' : 'Log');
|
||||
const label = kind === 'initialization' ? first.app : items.map(entry => entry.group_label || cleanMessage(entry).match(/^\[([^\]]+)\]/)?.[1]).find(Boolean) || first.entity || first.app;
|
||||
return node('div', `${name} · ${label}`, 'block-title');
|
||||
const kind = items.find(entry => entry.group_kind)?.group_kind;
|
||||
const name = kind || (items.length > 1 || first.trace_id ? 'Event' : 'Log');
|
||||
const label = items.map(entry => entry.group_label).find(Boolean) || first.entity || first.app;
|
||||
return node('div', kind ? name : `${name} · ${label}`, 'block-title');
|
||||
}
|
||||
function row(e) {
|
||||
const item = node('div', undefined, `row${selected === e.event_id ? ' selected' : ''}${recentEvents.has(e.event_id) ? ' recent-log' : ''}`);
|
||||
@@ -188,25 +187,24 @@
|
||||
detail.querySelector('.rows')?.remove();
|
||||
if (!detail.open) return;
|
||||
const rows = node('div', undefined, 'rows');
|
||||
const units = [], initGroups = new Map();
|
||||
const units = [], groupUnits = new Map();
|
||||
logs.forEach(e => {
|
||||
if (e.initialization_id) {
|
||||
if (!initGroups.has(e.initialization_id)) { const unit = { id: e.initialization_id, entries: [] }; initGroups.set(e.initialization_id, unit); units.push(unit); }
|
||||
initGroups.get(e.initialization_id).entries.push(e);
|
||||
if (e.group_id) {
|
||||
const key = `group:${e.group_id}`;
|
||||
if (!groupUnits.has(key)) { const unit = { key, entries: [] }; groupUnits.set(key, unit); units.push(unit); }
|
||||
groupUnits.get(key).entries.push(e);
|
||||
} else {
|
||||
const key = e.group_id ? `group:${e.group_id}` : e.kind === 'log' && e.trace_id ? `trace:${e.trace_id}` : undefined;
|
||||
const key = e.kind === 'log' && e.trace_id ? `trace:${e.trace_id}` : undefined;
|
||||
const previous = units[units.length - 1];
|
||||
if (key && previous && !previous.id && previous.key === key) previous.entries.push(e);
|
||||
else units.push({ key, entries: [e] });
|
||||
}
|
||||
});
|
||||
const startTime = unit => unit.id
|
||||
? (entries.find(e => e.app === app && e.initialization_id === unit.id && e.kind === 'initialization_started') || unit.entries[0]).time
|
||||
: unit.entries[0].time;
|
||||
const startTime = unit => unit.entries[0].time;
|
||||
units.sort((a, b) => startTime(a) - startTime(b));
|
||||
if (units.length > 150) rows.append(node('div', `${units.length - 150} older rows/groups: narrow the time range or search.`, 'more'));
|
||||
units.slice(-150).forEach(unit => {
|
||||
appendEventRows(rows, unit.entries, unit.id ? `initialization:${unit.id}` : undefined);
|
||||
appendEventRows(rows, unit.entries, unit.key);
|
||||
});
|
||||
detail.append(rows);
|
||||
const position = logScrollPositions.get(app);
|
||||
|
||||
Reference in new issue
Block a user