Files
VA-Log-Parser/commands/sortLog.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

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);
}
}