Skip to content

Commit 920cd9f

Browse files
add timestamp stripping utility
1 parent 5c9d17d commit 920cd9f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# evergreen-timestamp-utils
2+
3+
A simple utility for stripping timestamps from evergreen logs.
4+
5+
## usage
6+
7+
(macos)
8+
9+
```bash
10+
pbpaste | node index.mjs | pbcopy
11+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
import { pipeline } from 'stream/promises';
4+
5+
async function* lines(generator) {
6+
let data = '';
7+
8+
for await (const chunk of generator) {
9+
data += chunk;
10+
}
11+
12+
yield* data.split('\n');
13+
}
14+
15+
async function* removeEmptyLines(generator) {
16+
for await (const chunk of generator) {
17+
if (chunk.length) yield chunk;
18+
}
19+
}
20+
21+
async function* removeTimestamp(generator) {
22+
for await (const line of generator) {
23+
const timestamp = /\[.*\](?<rest>.*)/;
24+
const {
25+
groups: { rest }
26+
} = line.match(timestamp) ?? { groups: { rest: line } };
27+
yield rest;
28+
}
29+
}
30+
31+
async function* addNewlines(generator) {
32+
for await (const item of generator) {
33+
yield item;
34+
yield '\n';
35+
}
36+
}
37+
38+
await pipeline(
39+
process.stdin,
40+
lines,
41+
removeEmptyLines,
42+
removeTimestamp,
43+
addNewlines,
44+
process.stdout
45+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "evergreen-timestamp-utils",
3+
"version": "0.0.1",
4+
"description": "utility to strip timestamp from evergreen logs",
5+
"private": true,
6+
"main": "./index.mjs",
7+
"scripts": {},
8+
"engines": {
9+
"node": ">=16.20.1",
10+
"npm": ">=9.0.0"
11+
},
12+
"keywords": [],
13+
"author": "The MongoDB NodeJS Team <[email protected]>",
14+
"license": "Apache-2.0"
15+
}

0 commit comments

Comments
 (0)