-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog-history.js
More file actions
33 lines (30 loc) · 1.05 KB
/
Copy pathlog-history.js
File metadata and controls
33 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function isInternalStateReply(message) {
return (
/(?:Daytime is|The time is) \d+/u.test(message) ||
/There are \d+(?:\/\d+| of a max of \d+) players online/u.test(message)
);
}
function splitLogLine(line) {
const separator = line.indexOf(" ");
return {
at: separator > 0 ? line.slice(0, separator) : "",
message: separator > 0 ? line.slice(separator + 1) : line,
};
}
// State observation is intentionally absent from the client transcript, but
// its replies still exist in Docker's raw log and can crowd useful history out
// of a small `docker logs --tail` window. Read a larger raw window, discard
// that noise, and only forward the requested number of meaningful lines.
function trimVisibleLogHistory(data, limit) {
if (limit <= 0) return "";
const visible = data.split(/\r?\n/u).filter((line) => {
const { message } = splitLogLine(line);
return message && !isInternalStateReply(message);
});
return visible.slice(-limit).join("\n");
}
module.exports = {
isInternalStateReply,
splitLogLine,
trimVisibleLogHistory,
};