Files
VA-Log-Parser/commands/parseLogFile.js
luke-hagar-sp 9dca5ace6c Complete Rewrite
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.
2022-10-04 20:56:24 -05:00

36 lines
1.0 KiB
JavaScript

import fs from "fs";
import linebyline from "linebyline";
import ora from "ora";
import chalk from "chalk";
import cliProgress from "cli-progress";
import sortLog from "./sortLog.js";
const spinner = ora();
// create a new progress bar instance and use shades_classic theme
const bar1 = new cliProgress.SingleBar({
format: "{duration}sec | {bar} {percentage}% | {value}/{total} Bytes",
barCompleteChar: "\u2588",
barIncompleteChar: "\u2591",
hideCursor: true,
stopOnComplete: true,
});
export default function parseLogFile(LogFile) {
spinner.succeed(`Parsing Log File: ${LogFile}`);
let fileStats = fs.statSync(LogFile);
bar1.start(fileStats.size, 0, {
speed: "N/A",
});
let lines;
const rl = linebyline(LogFile);
rl.on("line", function (line, lineCount, byteCount) {
bar1.update(byteCount);
sortLog(line);
lines = lineCount;
});
rl.on("end", function (line, lineCount, byteCount) {
bar1.update(fileStats.size);
spinner.succeed(`Completed ${LogFile} / ${lines} Lines`);
});
}