Skip to content

Commit 436c581

Browse files
feat: add timestamp stripping utility (#48)
1 parent 5c9d17d commit 436c581

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "dbx-js-tools",
33
"private": true,
44
"workspaces": [
5-
"packages/bson-bench"
5+
"packages/bson-bench",
6+
"packages/evergreen-timestamp-utils"
67
],
78
"devDependencies": {
89
"@tsconfig/node16": "^16.1.4",
@@ -28,4 +29,4 @@
2829
"check:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint -v && ESLINT_USE_FLAT_CONFIG=false eslint --max-warnings=0 --ext '.js,.ts,.mts' packages/**/src packages/**/test",
2930
"fix:eslint": "npm run check:eslint -- --fix"
3031
}
31-
}
32+
}
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)