-
Notifications
You must be signed in to change notification settings - Fork 27
/
extractLogToPreview.js
33 lines (32 loc) · 804 Bytes
/
extractLogToPreview.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
const fs = require('fs');
const users = {};
const userId = user => {
if (!users[user]) {
users[user] = Object.keys(users).length;
}
return users[user];
};
const logObj = log => {
if (log[0] === 'timestamp') {
return;
}
return {
type: log[8],
itemId: log[9],
activityId: log[4],
value: log[10] ? JSON.parse(log[10]) : undefined,
payload: log[11] ? JSON.parse(log[11]) : undefined,
sessionId: '1',
userId: userId(log[2]),
instanceId: log[3],
timestamp: log[0]
};
};
const logstring = fs.readFileSync(process.argv[3] || 'log.tsv', 'utf-8');
const id = process.argv[2] && process.argv[2].trim();
logstring
.split('\n')
.map(x => x.split('\t'))
.filter(x => x[4] === id)
.map(x => logObj(x))
.forEach(x => console.info(JSON.stringify(x)));