forked from 7THStage/idigdoge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
29 lines (25 loc) · 771 Bytes
/
log.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
function makeMessage(args) {
var msgs = [];
for (var i = 0, a; i < args.length; i += 1) {
a = args[i];
if (a === null) msgs.push('null');
else if (a === undefined) msgs.push('undefined');
else if (typeof a === 'boolean') msgs.push(a ? 'true' : 'false');
else if (typeof a === 'string') msgs.push(a);
else if (typeof a === 'number') msgs.push(a.toString());
else if (typeof a === 'object') {
try {
if ('toString' in a) {
msgs.push(JSON.stringify(a));
}
} catch (e) {}
}
}
return msgs.join(' ');
};
exports.error = function() {
console.log('[ERROR]', new Date().toJSON(), process.pid, makeMessage(arguments));
};
exports.info = function() {
console.log('[INFO]', new Date().toJSON(), process.pid, makeMessage(arguments));
};