Skip to content

Commit cc08959

Browse files
committed
contrib: Make log visualizer work with CI & pytest
Update the log visualizer to detect logs coming from CI or python tests and be able to render them. ChangelogNone
1 parent 4d10da2 commit cc08959

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

contrib/log_visualizer.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,48 @@
154154
document.getElementById('filter_error').innerText = error.message;
155155
}
156156
}
157+
function detect_ci_logs(logs)
158+
{
159+
nodes = new Set()
160+
Array.from(logs.matchAll(/[0-9\-T:.Z]+ (lightningd-[0-9]+) /g)).forEach(match => {
161+
nodes.add(match[1]);
162+
});
163+
var keys = [...nodes];
164+
var node = keys.at(0);
165+
166+
if (nodes.size > 1) {
167+
str = "Continous Integration log with multiple nodes detected.\n\nWhich would you like rendered?\n\nNodes detected:\n" + keys.join("\n");
168+
node = prompt(str, keys[0]).trim();
169+
}
170+
171+
return node ? new RegExp(`[0-9\-T:.Z]+ ${node} `, "g") : null;
172+
}
173+
function detect_pytest_logs(logs)
174+
{
175+
nodes = new Set()
176+
Array.from(logs.matchAll(/(lightningd-[0-9]+) /g)).forEach(match => {
177+
nodes.add(match[1]);
178+
});
179+
var keys = [...nodes];
180+
var node = keys.at(0);
181+
182+
if (nodes.size > 1) {
183+
str = "Python Test log with multiple nodes detected.\n\nWhich would you like rendered?\n\nNodes detected:\n" + keys.join("\n");
184+
node = prompt(str, keys[0]).trim();
185+
}
186+
187+
return node ? new RegExp(`^${node} `, "g") : null;
188+
}
189+
function detect_log_prefix(logs)
190+
{
191+
var ci = detect_ci_logs(logs)
192+
if (ci)
193+
return ci;
194+
var pytest = detect_pytest_logs(logs)
195+
if (pytest)
196+
return pytest;
197+
return null;
198+
}
157199
function do_render(logs, area)
158200
{
159201
var d = document;
@@ -168,11 +210,21 @@
168210
while(sheet.cssRules.length)
169211
sheet.deleteRule(0);
170212

213+
prefix = detect_log_prefix(logs);
214+
171215
for(line of logs.split("\n")) {
172216
line = line.trim()
173217
if(!line.length)
174218
continue;
175219

220+
/* Detect and eat node prefix. If no prefix match, ignore line */
221+
if (prefix) {
222+
prefix_match = line.match(prefix);
223+
if(!prefix_match)
224+
continue;
225+
line = line.slice(prefix_match[0].length);
226+
}
227+
176228
info = parseLogLine(line);
177229

178230
if(info.msg.startsWith('Server started with public key'))

0 commit comments

Comments
 (0)