diff --git a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js index dbccf3a3d..bd782256c 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/Flow.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/Flow.js @@ -93,7 +93,7 @@ class Flow { * @param {[type]} msg [description] * @return {[type]} [description] */ - log(msg) { + info(msg) { Log.log({ id: this.id||"global", 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. diff --git a/packages/node_modules/@node-red/runtime/lib/flows/index.js b/packages/node_modules/@node-red/runtime/lib/flows/index.js index 350115f81..b31dc7755 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/index.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/index.js @@ -698,7 +698,8 @@ const flowAPI = { getNode: getNode, handleError: () => false, handleStatus: () => false, - getSetting: k => flowUtil.getEnvVar(k) + getSetting: k => flowUtil.getEnvVar(k), + log: m => log.log(m) } diff --git a/packages/node_modules/@node-red/runtime/lib/nodes/Node.js b/packages/node_modules/@node-red/runtime/lib/nodes/Node.js index dfc8b5ed1..faf07bda5 100644 --- a/packages/node_modules/@node-red/runtime/lib/nodes/Node.js +++ b/packages/node_modules/@node-red/runtime/lib/nodes/Node.js @@ -486,16 +486,14 @@ function log_helper(self, level, msg) { if (self._alias) { o._alias = self._alias; } - if (self._flow) { - o.path = self._flow.path; - } + if (self.z) { o.z = self.z; } if (self.name) { o.name = self.name; } - Log.log(o); + self._flow.log(o); } /** * Log an INFO level message diff --git a/test/unit/@node-red/runtime/lib/nodes/Node_spec.js b/test/unit/@node-red/runtime/lib/nodes/Node_spec.js index df362dc85..532fa96e7 100644 --- a/test/unit/@node-red/runtime/lib/nodes/Node_spec.js +++ b/test/unit/@node-red/runtime/lib/nodes/Node_spec.js @@ -653,42 +653,30 @@ describe('Node', function() { describe('#log', function() { 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 = {}; - sinon.stub(Log, 'log', function(msg) { - loginfo = msg; - }); n.log("a log message"); should.deepEqual({level:Log.INFO, id:n.id, type:n.type, msg:"a log message",z:'789'}, loginfo); - Log.log.restore(); 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 = {}; - sinon.stub(Log, 'log', function(msg) { - loginfo = msg; - }); n.log("a log message"); should.deepEqual({level:Log.INFO, id:n.id, name: "barney", type:n.type, msg:"a log message",z:'789'}, loginfo); - Log.log.restore(); done(); }); }); describe('#warn', function() { 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 = {}; - sinon.stub(Log, 'log', function(msg) { - loginfo = msg; - }); n.warn("a warning"); should.deepEqual({level:Log.WARN, id:n.id, type:n.type, msg:"a warning",z:'789'}, loginfo); - Log.log.restore(); done(); }); }); @@ -696,7 +684,8 @@ describe('Node', function() { describe('#error', function() { it('handles a null error message', function(done) { var flow = { - handleError: sinon.stub() + handleError: sinon.stub(), + log:sinon.stub() } var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'}); var message = {a:1}; @@ -712,7 +701,8 @@ describe('Node', function() { it('produces an error message', function(done) { var flow = { - handleError: sinon.stub() + handleError: sinon.stub(), + log:sinon.stub() } var n = new RedNode({_flow:flow, id:'123',type:'abc',z:'789'}); var message = {a:2};