I have some log files from a Gameserver that I want to evaluate, there are some problems I ran into while doing so. I am reading the log file line by line:
const fs = require('fs');
const readline = require('readline');
async function processLineByLine() {
const fileStream = fs.createReadStream('log.adm');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
for await (const line of rl) {
console.log(`Line from file: ${line}`);
}
}
}
processLineByLine();
The Log file is different for each line, here is a short example:
00:03:06 | Player "XXX"(id=Unknown) has been disconnected
00:03:41 | ##### PlayerList log: 6 players
00:03:41 | Player "XXX" (id=XXX= pos=<13849, 2898.0, 32.6>)
00:03:41 | Player "XXX" (id=XXX= pos=<12895, 8573.3, 6.2>)
00:03:41 | Player "XXX (2)" (id=XXX= pos=<2471.7, 5129.1, 193.7>)
00:03:41 | Player "XXX" (id=XXX= pos=<13856, 2883.2, 32.7>)
00:03:41 | Player "XXX" (id=XXX= pos=<2480.8, 5153.3, 190.3>)
00:03:41 | Player "XXX" (id=XXX= pos=<12895.7, 8573.6, 6.2>)
00:03:41 | #####
00:04:10 | Player "XXX (2)" (id= pos=<2469.8, 5130.2, 193.7>)[HP: 45] hit by Player "XXX" (id=XXX= pos=<2479.9, 5116.7, 193.2>) into Torso(23) for 55 damage (Bullet_762x39) with KA-M from 16.8674 meters
00:04:18 | Player "XXX"(id=Unknown) has been disconnected
00:08:40 | ##### PlayerList log: 6 players
00:08:40 | Player "XXX" (id=XXX= pos=<13843.5, 2894.8, 32.5>)
00:08:40 | Player "XXX" (id=XXX= pos=<13269.8, 3362.0, 7.7>)
00:08:40 | Player "XXX (2)" (id=XXX= pos=<2512.3, 5083.0, 193.5>)
00:08:40 | Player "XXX" (id=XXX= pos=<13844.5, 2894.5, 32.3>)
00:08:40 | Player "XXX" (id=XXX= pos=<2467.7, 5124.0, 193.3>)
00:08:40 | Player "XXX" (id=XXX= pos=<13270.2, 3361.4, 7.7>)
00:08:40 | #####
so I've tried to split the line on certain characters but there is nothing they really have in common. My goal is to get the relevant information in its own variable, for each player so like: Time, PlayerName, ID, Position and the event (e.g got hit, placed something)
for the event, I think it would be best to ask for different if clauses or switch statements, but first of all I need to get the important data for every line.
question from:
https://stackoverflow.com/questions/65860932/evaluate-log-files-line-by-line-in-javascript