mirror of
https://github.com/LukeHagar/VA-Log-Parser.git
synced 2025-12-06 12:57:45 +00:00
Adjusted functionality to account for significantly larger files Better organizational Structure Added Progress Bars, added support for multiple concurrent files at once Adjusted flow so logs are parsed and sorted as lines are read and identified, this should improve performance, reliability, and error reporting.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import fs from "fs";
|
|
import linebyline from "linebyline";
|
|
import ora from "ora";
|
|
import cliProgress from "cli-progress";
|
|
import sortLog from "./sortLog.js";
|
|
|
|
const spinner = ora();
|
|
|
|
let files;
|
|
|
|
// create new container
|
|
const multibar = new cliProgress.MultiBar({
|
|
format: "{duration}sec | {bar} {percentage}% | {value}/{total} Bytes",
|
|
barCompleteChar: "\u2588",
|
|
barIncompleteChar: "\u2591",
|
|
hideCursor: true,
|
|
stopOnComplete: true,
|
|
});
|
|
|
|
async function startParse(file) {
|
|
const rl = linebyline(file.file);
|
|
rl.on("line", function (line, lineCount, byteCount) {
|
|
file.bar.update(byteCount);
|
|
sortLog(line);
|
|
});
|
|
rl.on("end", function (line, lineCount, byteCount) {
|
|
file.bar.update(file.stats.size);
|
|
});
|
|
}
|
|
|
|
export default function parseMultipleLogFiles(logFiles) {
|
|
spinner.succeed(`Parsing Log Files: ${logFiles}`);
|
|
files = logFiles.map((file, index) => {
|
|
let stats = fs.statSync(file);
|
|
return {
|
|
file,
|
|
stats,
|
|
bar: multibar.create(stats.size, 0),
|
|
index,
|
|
};
|
|
});
|
|
files.forEach((file) => {
|
|
startParse(file);
|
|
});
|
|
}
|