Skip to content

Commit 87e4d1e

Browse files
committed
fix: quieter and optional jsonl-reader logging
1 parent 6fb87bb commit 87e4d1e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

extensions/ql-vscode/src/common/jsonl-reader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { statSync } from "fs";
22
import { createReadStream } from "fs-extra";
33
import { createInterface } from "readline";
4-
import { extLogger } from "./logging/vscode";
54

65
/**
76
* Read a file consisting of multiple JSON objects. Each object is separated from the previous one
@@ -13,12 +12,13 @@ import { extLogger } from "./logging/vscode";
1312
export async function readJsonlFile<T>(
1413
path: string,
1514
handler: (value: T) => Promise<void>,
15+
logger?: { log: (message: string) => void },
1616
): Promise<void> {
1717
function parseJsonFromCurrentLines() {
1818
try {
1919
return JSON.parse(currentLineSequence.join("\n")) as T;
2020
} catch (e) {
21-
void extLogger.log(
21+
void logger?.log(
2222
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2323
`Error: Failed to parse at line ${lineCount} of ${path} as JSON: ${(e as any)?.message ?? "UNKNOWN REASON"}. Problematic line below:\n${JSON.stringify(currentLineSequence, null, 2)}`,
2424
);
@@ -27,12 +27,12 @@ export async function readJsonlFile<T>(
2727
}
2828

2929
function logProgress() {
30-
void extLogger.log(
30+
void logger?.log(
3131
`Processed ${lineCount} lines with ${parseCounts} parses...`,
3232
);
3333
}
3434

35-
void extLogger.log(
35+
void logger?.log(
3636
`Parsing ${path} (${statSync(path).size / 1024 / 1024} MB)...`,
3737
);
3838
const fileStream = createReadStream(path, "utf8");
@@ -54,7 +54,7 @@ export async function readJsonlFile<T>(
5454
currentLineSequence.push(line);
5555
}
5656
lineCount++;
57-
if (lineCount % 100000 === 0) {
57+
if (lineCount % 1000000 === 0) {
5858
logProgress();
5959
}
6060
}

0 commit comments

Comments
 (0)