mirror of
https://github.com/LukeHagar/VA-Log-Parser.git
synced 2025-12-06 04:21:55 +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.
33 lines
966 B
JavaScript
33 lines
966 B
JavaScript
import fs from "fs";
|
|
|
|
export default async function sortLog(line) {
|
|
try {
|
|
const Obj = JSON.parse(line);
|
|
const parsedLine = {
|
|
date: new Date(Obj["@timestamp"]).toDateString(),
|
|
error: line.includes("error") || line.includes("exception"),
|
|
...Obj,
|
|
};
|
|
let logPath;
|
|
let folderPath;
|
|
if (parsedLine.error) {
|
|
folderPath = `./${parsedLine.org}/${
|
|
parsedLine.date
|
|
}/Errors/${parsedLine.logger_name.replaceAll(".", "-")}`;
|
|
} else {
|
|
folderPath = `./${parsedLine.org}/${
|
|
parsedLine.date
|
|
}/Everything/${parsedLine.logger_name.replaceAll(".", "-")}`;
|
|
}
|
|
logPath = `${folderPath}/log.json`;
|
|
if (fs.existsSync(folderPath)) {
|
|
fs.appendFileSync(logPath, `${JSON.stringify(parsedLine)}\n`);
|
|
} else {
|
|
fs.mkdirSync(folderPath, { recursive: true });
|
|
fs.writeFileSync(logPath, `${JSON.stringify(parsedLine)}\n`);
|
|
}
|
|
} catch (err) {
|
|
// console.debug(err);
|
|
}
|
|
}
|