forked from farpoint/meteor-winston-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (48 loc) · 1.37 KB
/
server.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
49
50
51
52
53
54
55
56
var util = Npm.require("util"),
lastMessage = ''; // The message to return to the user
/**
A custom transport for winston that is used by winston-client to send log messages back to the client
@class MeteorClient
*/
var MeteorClient = Winston.transports.MeteorClient = function (options) {
this.name = 'meteorClient';
this.level = options.level || 'silly';
};
util.inherits(MeteorClient, Winston.Transport);
/**
Determine if a dictionary is empty
@method isEmpty
@param {Object} obj The object to test
@return Boolean
*/
function isEmpty(obj) {
if (Object.keys) { // EMCAScript 5 support
return Object.keys(obj).length === 0;
} else { // Old school
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
}
MeteorClient.prototype.log = function (level, msg, meta, callback) {
// @TODO: Make the log message conform better to Winston's own output
lastMessage = level + ': ' + msg;
if (!isEmpty(meta) && JSON.stringify) {
lastMessage += '\nmeta = ' + JSON.stringify(meta)
}
callback(null, true);
};
Winston.add(Winston.transports.MeteorClient, {});
Meteor.methods({
/**
A rough equivalent to Winston.log() over Meteor.call.
Takes the same arguments
*/
'winston-client.log': function() {
check(arguments, [Match.Any]);
Winston.log.apply(null, arguments);
return lastMessage;
}
});