Skip to content

Instantly share code, notes, and snippets.

@razorcd
Created March 23, 2018 23:47
Show Gist options
  • Save razorcd/3831f6d5863ba8243381085db6b6a843 to your computer and use it in GitHub Desktop.
Save razorcd/3831f6d5863ba8243381085db6b6a843 to your computer and use it in GitHub Desktop.
Log parser
var fs = require('fs');
var content = readFile("19_3_2018log.txt");
var allLines = getLines(content);
console.log("All lines:");
console.log(allLines);
var result = allLines.map(line => parseLineToObject(line));
console.log("Result:");
console.log(result);
writeFile("result.json", JSON.stringify(result));
function readFile(filename) {
console.log("Reading file.");
return fs.readFileSync(filename, 'utf8');
}
function writeFile(filename, data) {
console.log("Writing file.");
fs.writeFileSync(filename, data, {encoding:'utf8',flag:'w'});
}
function getLines(content) {
var lineRegex = /"launch:.+\d\d:\d\d:\d\d\"\n/g;
return content.match(lineRegex);
}
function parseLineToObject(line) {
var parts = line.split(" ");
return {
obj: parts[4],
time: parts[6].replace("\"", "").trim()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment