Merge pull request #576 from Belphemur/function-logger

Adding an Object Node to the sandbox of a function node
This commit is contained in:
Nick O'Leary
2015-03-07 23:37:00 +00:00
4 changed files with 96 additions and 3 deletions

View File

@@ -196,8 +196,14 @@
'</span>';
// NOTE: relying on function error to have a "type" that all other msgs don't
if (o.hasOwnProperty("type") && (o.type === "function")) {
msg.className = 'debug-message debug-message-level-20';
msg.innerHTML += '<span class="debug-message-topic">[function] : (error)</span>';
var errorLvlType = 'error';
var errorLvl = 20;
if (o.hasOwnProperty("level") && o.level === 30) {
errorLvl = 30;
errorLvlType = 'warn'
}
msg.className = 'debug-message debug-message-level-' + errorLvl;
msg.innerHTML += '<span class="debug-message-topic">[function] : (' + errorLvlType + ')</span>';
} else {
msg.innerHTML += '<span class="debug-message-topic">'+(o.topic?topic+' : ':'')+
(o.property?'[msg.'+property+']':'[msg]')+" : "+typ+'</span>';

View File

@@ -39,6 +39,13 @@
<p>The message is passed in as a JavaScript object called <code>msg</code>.</p>
<p>By convention it will have a <code>msg.payload</code> property containing
the body of the message.</p>
<p>If your node need to log anything use the <code>node</code> object:
<ul>
<li>Info: <code>node.log(msg);</code></li>
<li>Warning: <code>node.warn(msg);</code></li>
<li>Error: <code>node.error(msg);</code></li>
</ul>
</p>
<p>The function should return the messages it wants to pass on to the next nodes
in the flow. It can return:</p>
<ul>

View File

@@ -21,6 +21,7 @@ module.exports = function(RED) {
function FunctionNode(n) {
RED.nodes.createNode(this,n);
var node = this;
this.name = n.name;
this.func = n.func;
var functionText = "var results = null; results = (function(msg){\n"+this.func+"\n})(msg);";
@@ -29,6 +30,17 @@ module.exports = function(RED) {
console:console,
util:util,
Buffer:Buffer,
node: {
log : function() {
node.log.apply(node, arguments);
},
error: function(){
node.error.apply(node, arguments);
},
warn: function() {
node.warn.apply(node, arguments);
}
},
context: {
global:RED.settings.functionGlobalContext || {}
}