1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Refactor common log code.

This commit is contained in:
Mark Hindess 2014-07-09 07:42:34 +01:00
parent 0a7bd848c6
commit d371511d1d

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" }
*/