Refactor common log code.

This commit is contained in:
Mark Hindess 2014-07-09 07:42:34 +01:00
parent 0a7bd848c6
commit d371511d1d
1 changed files with 14 additions and 15 deletions

View File

@ -119,27 +119,26 @@ Node.prototype.receive = function(msg) {
this.emit("input",msg);
}
function log_helper(self, level, msg) {
var o = {level:level, id:self.id, type:self.type, msg:msg};
if (self.name) {
o.name = self.name;
}
self.emit("log",o);
}
Node.prototype.log = function(msg) {
var o = {level:'log',id:this.id, type:this.type, msg:msg};
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
log_helper(this, 'log', msg);
}
Node.prototype.warn = function(msg) {
var o = {level:'warn',id:this.id, type:this.type, msg:msg};
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
log_helper(this, 'warn', msg);
}
Node.prototype.error = function(msg) {
var o = {level:'error',id:this.id, type:this.type, msg:msg};
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
log_helper(this, 'error', msg);
}
/**
* status: { fill:"red|green", shape:"dot|ring", text:"blah" }
*/