-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (41 loc) · 925 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
46
47
48
var util = require('util');
var Log = function(bucket) {
var db = require('riak-js').getClient({debug:false});
var bucketName = bucket || 'node-rlog';
function formatMsg(msg) {
var _msg = [];
for (i in msg) {
if (typeof msg[i] === 'object') {
_msg.push(util.inspect(msg[i]));
} else {
_msg.push(msg[i]);
}
}
return _msg.join(' ');
}
function now() {
return new Date().getTime();
}
function save(level, msg) {
db.save(bucketName, now(), msg, { level: level });
}
return {
debug: function() {
save('debug', formatMsg(arguments));
},
info: function() {
save('info', formatMsg(arguments));
},
warn: function() {
save('warn', formatMsg(arguments));
},
error: function() {
save('error', formatMsg(arguments));
}
}
}
module.exports = {
getLogger: function(b) {
return new Log(b);
}
}