Public
Edited
Oct 18, 2023
Paused
Insert cell
Insert cell
logs_stream = await FileAttachment("logs.ndjson").stream()
Insert cell
text_stream = logs_stream.pipeThrough(new TextDecoderStream())
Insert cell
reader = text_stream.getReader()
Insert cell
/*values = {
while (true) {
const { done, value } = await reader.read();
if (!done && value != null) {
mutable buffer = mutable buffer + value
} else {
await new Promise(resolve => setTimeout(resolve, 500));
}
let splits = buffer.split("\n");
while (splits.length > 1) {
//await new Promise(resolve => setTimeout(resolve, 500));
let json = splits.shift();
if (splits.length > 0) {
mutable buffer = splits.join("\n");
}
mutable data = [...data, JSON.parse(json)];
yield JSON.parse(json).log;
}
}
}*/
Insert cell
async function* parse_logs (reader) {
let buffer = ""
while (true) {
const { done, value } = await reader.read();
if (!done && value != null) {
buffer = buffer + value
} else {
await new Promise(resolve => setTimeout(resolve, 500));
}
let splits = buffer.split("\n");
while (splits.length > 1) {
//await new Promise(resolve => setTimeout(resolve, 500));
let json = splits.shift();
if (splits.length > 0) {
buffer = splits.join("\n");
}
yield JSON.parse(json);
}
}
}
Insert cell
mutable data = [];
Insert cell
json = parse_logs(reader)
Insert cell
Insert cell
table = htl.html`<table id="logs" style="white-space: break-spaces; font-family: monospace;"><tbody></tbody></table>`

Insert cell
{
table.querySelector("tbody").appendChild(htl.html`<tr><td>${json["log"]}</td></tr>`);
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more