-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintlog.js
More file actions
36 lines (31 loc) · 780 Bytes
/
printlog.js
File metadata and controls
36 lines (31 loc) · 780 Bytes
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
'use strict';
var fs = require('fs');
var chalk = require('chalk');
var logData = fs.readFileSync(process.argv[2], 'utf8');
var lines = logData.split('\n');
var lineCount = 0;
lines.forEach(function(line) {
if (line.length > 0) {
try {
var entry = JSON.parse(line);
}
catch (e) {
console.log("JSON parse error: " + e);
}
var color = 'gray';
var entryString = entry['timestamp'] + " " + entry['level'] + ": " + entry['message'];
switch(entry['level']) {
case 'error':
console.log(chalk.red(entryString));
break;
case 'web':
console.log(chalk.cyan(entryString));
break;
case 'info':
console.log(chalk.green(entryString));
break;
default:
console.log(chalk.white(entryString));
}
}
});