This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxlp.js
98 lines (78 loc) · 2.88 KB
/
xlp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
const colors = require('colors');
const LineByLineReader = require('line-by-line');
const program = require('commander');
const chokidar = require('chokidar');
const fs = require("fs");
const path = require('path');
program
.version('0.0.1')
.option('-p, --path [path]', 'Path to xbea log')
.option('-f, --filter [path]', 'Filter by Regen')
.parse(process.argv);
const DEFAULT_PATH = 'C:/Xbea/Logs/VIP/';
const PATH = program.path || DEFAULT_PATH;
const FILTER = program.filter;
function outputLog(line, repgenName) {
if (line.search(/Request:/) > 0) {
const repgenResponse = line.replace(/^.*Request:\s(.*)$/, '$1')
console.log(`\r\n\tRequest of ${repgenName.replace(/^G/, '')}\r\n`.blue.bold);
console.log(`\t${repgenResponse.replace(/~/g, '\r\n\t')}`.cyan);
}
if (line.search(/Response:/) > 0) {
const repgenResponse = line.replace(/^.*Response:\s(.*)$/, '$1')
console.log(`\r\n\tResponse of ${repgenName}\r\n`.blue.bold);
console.log(`\t${repgenResponse.replace(/\|/g, '\r\n\t').replace(/~JRGLINE=/g, '').replace(/~/g, '\r\n\t')}`.green);
console.log('\r\n\t-------------------------------------\r\n'.grey);
}
}
function parseLog(path) {
const lr = new LineByLineReader(path);
const lines = [];
lr.on('line', function (line) {
lines.push(line)
});
lr.on('end', function () {
Array.from(new Set(lines)).forEach((line) => {
if (line.search(/SymConnectClient/) > 0) {
const repgenNamePattern = line.match(/[.A-Z]+\.RG/);
const repgenName = repgenNamePattern && repgenNamePattern.length ? repgenNamePattern[0].replace(/^G/,'') : line;
if(repgenName) {
if(FILTER && FILTER === repgenName || repgenName === line) {
outputLog(line, repgenName)
}
if(!FILTER) {
outputLog(line, repgenName)
}
}
}
});
});
}
if (PATH) {
function getLastModifiedFile(path) {
const files = fs.readdirSync(path);
const sortedFiles = files.filter((item)=>{
return fs.statSync(path + item).isFile();
}).sort(function(a, b) {
return fs.statSync(path + a).mtime.getTime() -
fs.statSync(path + b).mtime.getTime();
});
if(sortedFiles.length) {
return path + sortedFiles[0]
} else {
return null;
}
}
try {
const lastFile = fs.statSync(PATH).isFile() ? PATH : getLastModifiedFile(PATH);
chokidar.watch(PATH, {ignored: /(^|[\/\\])\../}).on('all', (event, path) => {
if(lastFile) {
parseLog(lastFile);
}
})
}
catch(err) {
console.log(`Path ${PATH} does't exist :(`.cyan);
}
}