-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.filterImpressLogs.js
39 lines (33 loc) · 1.17 KB
/
2.filterImpressLogs.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
let fs = require('fs'),
path =require('path');
const dateLength = 10,
datetimeLength = 24;
function makeFilename(date, logType) {
return `${date}-${logType}.log`;
}
function isTimeBetween(startDate, endDate, line) {
let date = Date.parse(line.substring(0, datetimeLength));
let res = date - startDate >= 0 && endDate - date > 0;
return res;
}
function getLogsBetween(startTime, endTime) {
let dates = ['2016-08-01', '2016-08-02', '2016-08-05', '2016-08-06'],
logTypes = ['debug', 'error', 'node', 'server', 'slow', 'warning'];
dates.forEach(date => {
let startDate = Date.parse(`${date}T${startTime}Z`),
endDate = Date.parse(`${date}T${endTime}Z`);
logTypes.forEach(logType => {
let filename = 'logs' + path.sep + makeFilename(date, logType);
fs.readFile(filename, function(err, data) {
if (err) return;
data.toString().split('\n').filter(
isTimeBetween.bind(null, startDate, endDate)
// x => isTimeBetween(startDate, endDat, x)
).forEach(logRecord => {
console.log(`${logType}: ${logRecord}`);
});
});
});
});
}
getLogsBetween('17:00:00.000', '17:02:00.000');