-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
47 lines (34 loc) · 950 Bytes
/
index.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
var util = require('util');
var Transform = require('readable-stream/transform');
var fallback = new Transform({objectMode: true});
var severityNames = [
'EMERG',
'ALERT',
'CRIT',
'ERROR',
'WARN',
'NOTICE',
'INFO',
'DEBUG'
];
fallback._transform = function(data, encoding, cb) {
var severity = severityNames[data.severity] || 'DEBUG';
data.timestamp = data.timestamp || new Date();
if (!data.message){
if (data.arguments) {
data.message = util.format.apply(this, data.arguments) + '\n';
} else {
data.message = 'something wrong, arguments are not specified: ' +
util.inspect(data) + '\n';
}
}
var str = data.timestamp.toLocaleTimeString() + '.' +
data.timestamp.getMilliseconds();
if (data.namespace) {
str += ' [' + data.namespace + ']';
}
str += ' <' + severity + '> ' + data.message;
cb(null, str);
};
fallback.pipe(process.stdout);
module.exports = fallback;