Nodes log via parent flow to allow flow-info to be added

This commit is contained in:
Nick O'Leary 2020-09-02 19:33:12 +01:00 committed by Nick O'Leary
parent 9a660f3fe9
commit 0c9fd25d3e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 23 additions and 23 deletions

View File

@ -93,7 +93,7 @@ class Flow {
* @param {[type]} msg [description] * @param {[type]} msg [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
log(msg) { info(msg) {
Log.log({ Log.log({
id: this.id||"global", id: this.id||"global",
level: Log.INFO, level: Log.INFO,
@ -116,6 +116,17 @@ class Flow {
}) })
} }
/**
* [log description]
* @param {[type]} msg [description]
* @return {[type]} [description]
*/
log(msg) {
if (!msg.path) {
msg.path = this.path;
}
this.parent.log(msg);
}
/** /**
* Start this flow. * Start this flow.

View File

@ -698,7 +698,8 @@ const flowAPI = {
getNode: getNode, getNode: getNode,
handleError: () => false, handleError: () => false,
handleStatus: () => false, handleStatus: () => false,
getSetting: k => flowUtil.getEnvVar(k) getSetting: k => flowUtil.getEnvVar(k),
log: m => log.log(m)
} }

View File

@ -486,16 +486,14 @@ function log_helper(self, level, msg) {
if (self._alias) { if (self._alias) {
o._alias = self._alias; o._alias = self._alias;
} }
if (self._flow) {
o.path = self._flow.path;
}
if (self.z) { if (self.z) {
o.z = self.z; o.z = self.z;
} }
if (self.name) { if (self.name) {
o.name = self.name; o.name = self.name;
} }
Log.log(o); self._flow.log(o);
} }
/** /**
* Log an INFO level message * Log an INFO level message

View File

@ -653,42 +653,30 @@ describe('Node', function() {
describe('#log', function() { describe('#log', function() {
it('produces a log message', function(done) { it('produces a log message', function(done) {
var n = new RedNode({id:'123',type:'abc',z:'789'}); var n = new RedNode({id:'123',type:'abc',z:'789', _flow: {log:function(msg) { loginfo = msg;}}});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) {
loginfo = msg;
});
n.log("a log message"); n.log("a log message");
should.deepEqual({level:Log.INFO, id:n.id, should.deepEqual({level:Log.INFO, id:n.id,
type:n.type, msg:"a log message",z:'789'}, loginfo); type:n.type, msg:"a log message",z:'789'}, loginfo);
Log.log.restore();
done(); done();
}); });
it('produces a log message with a name', function(done) { it('produces a log message with a name', function(done) {
var n = new RedNode({id:'123', type:'abc', name:"barney", z:'789'}); var n = new RedNode({id:'123', type:'abc', name:"barney", z:'789', _flow: {log:function(msg) { loginfo = msg;}}});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) {
loginfo = msg;
});
n.log("a log message"); n.log("a log message");
should.deepEqual({level:Log.INFO, id:n.id, name: "barney", should.deepEqual({level:Log.INFO, id:n.id, name: "barney",
type:n.type, msg:"a log message",z:'789'}, loginfo); type:n.type, msg:"a log message",z:'789'}, loginfo);
Log.log.restore();
done(); done();
}); });
}); });
describe('#warn', function() { describe('#warn', function() {
it('produces a warning message', function(done) { it('produces a warning message', function(done) {
var n = new RedNode({id:'123',type:'abc',z:'789'}); var n = new RedNode({id:'123',type:'abc',z:'789', _flow: {log:function(msg) { loginfo = msg;}}});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) {
loginfo = msg;
});
n.warn("a warning"); n.warn("a warning");
should.deepEqual({level:Log.WARN, id:n.id, should.deepEqual({level:Log.WARN, id:n.id,
type:n.type, msg:"a warning",z:'789'}, loginfo); type:n.type, msg:"a warning",z:'789'}, loginfo);
Log.log.restore();
done(); done();
}); });
}); });
@ -696,7 +684,8 @@ describe('Node', function() {
describe('#error', function() { describe('#error', function() {
it('handles a null error message', function(done) { it('handles a null error message', function(done) {
var flow = { var flow = {
handleError: sinon.stub() handleError: sinon.stub(),
log:sinon.stub()
} }
var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'}); var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'});
var message = {a:1}; var message = {a:1};
@ -712,7 +701,8 @@ describe('Node', function() {
it('produces an error message', function(done) { it('produces an error message', function(done) {
var flow = { var flow = {
handleError: sinon.stub() handleError: sinon.stub(),
log:sinon.stub()
} }
var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'}); var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'});
var message = {a:2}; var message = {a:2};