Files
VA-Log-Parser/commands/parseLogFile.js
luke-hagar-sp eedd8a7501 Update parseLogFile.js
Removed unused import
2022-10-18 14:52:26 -05:00

35 lines
1005 B
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();
// 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`);
});
}