-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.imperative.js
49 lines (36 loc) · 1016 Bytes
/
index.imperative.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
import { log, readFile, writeFile } from './helpers/index';
console.clear();
const path = process.env.FILE_PATH;
log('green', 'Read file', path);
let fileData;
try {
fileData = readFile(path);
} catch (e) {
log('red', 'Error', e.message);
}
const logs = fileData.match(/[^\r\n]+/g);
const logsWithErrors = [];
for (let i = 0; i < logs.length; i++) {
const logData = logs[i].match(
/([\d-:,\s]+)\s\(.+\)\s(\w+)\s+\(([^)]+)\)\s(.+)/,
);
const logInfo = {
time: logData[1],
type: logData[2],
component: logData[3],
message: logData[4],
};
if (
(logInfo.type === 'ERROR' || logInfo.type === 'WARN') &&
logInfo.component === 'search-interfaces-infra'
) {
logsWithErrors.push(logInfo);
}
}
const formatedLogs = JSON.stringify(logsWithErrors, null, 2);
log('green', 'Write to file', formatedLogs);
try {
writeFile('errorsLog.json', '../', formatedLogs);
} catch (e) {
log('red', 'Error', e.message);
}