-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_server.js
60 lines (50 loc) · 1.33 KB
/
debug_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
57
58
59
60
Meteor.Debug.clients = 0;
Meteor.Debug.logs = new Meteor.Collection(null);
Meteor.Debug.toArray = function(obj){
var arr = [];
for (var i in obj){
arr.push(obj[i]);
}
return arr;
};
Meteor.Debug.broadcast = function(method){
var args = this.toArray(arguments);
args.shift();
if (Meteor.Debug.clients > 0){
Meteor.Debug.logs.update({id : "0"}, {$set : {method : method, data: args}});
}
else{
console[method].apply(console, args);
}
};
Meteor.Debug.log = function(){
var args = this.toArray(arguments);
args.unshift("log");
this.broadcast.apply(this, args);
};
Meteor.Debug.warn = function(){
var args = this.toArray(arguments);
args.unshift("warn");
this.broadcast.apply(this, args);
};
Meteor.Debug.info = function(){
var args = this.toArray(arguments);
args.unshift("info");
this.broadcast.apply(this, args);
};
Meteor.Debug.logs.insert({id : "0"});
Meteor.publish("remote-debug", function() {
Meteor.Debug.clients++;
this.onStop(function(){
Meteor.Debug.clients--;
});
var self = this;
Meteor.Debug.logs.find({id : "0"}).observeChanges({
added : function(id, fields){
self.added("remote-debug", id, fields);
},
changed : function(id, fields){
self.changed("remote-debug", id, fields);
}
});
});