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

Tweaks to Debug. realigned UI to be consistent with other nodes, Increased maxlength limit to 1000, Made circular object handling the default.

This commit is contained in:
Dave C-J 2013-09-17 11:11:09 +01:00
parent 4b119c065a
commit d3ed9afe03
3 changed files with 25 additions and 29 deletions

View File

@ -16,13 +16,15 @@
<script type="text/x-red" data-template-name="debug">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<label for="node-input-complete"><i class="icon-list"></i> Output</label>
<select type="text" id="node-input-complete" style="display: inline-block; width: auto; vertical-align: top;">
<option value=false>Payload only</option>
<option value=true>Complete msg object</option>
</select>
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-complete" placeholder="Complete" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-complete" style="width: 70%;">Show complete msg object ?</label>
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>

View File

@ -19,24 +19,27 @@ var RED = require("../../red/red");
var util = require("util");
var ws = require('ws');
var events = require("events");
var debuglength = RED.settings.debugMaxLength||512;
var debuglength = RED.settings.debugMaxLength||1000;
function DebugNode(n) {
RED.nodes.createNode(this,n);
this.name = n.name;
this.complete = n.complete;
this.active = (n.active == null)||n.active;
this.on("input",function(msg) {
if (this.active) {
if (msg.payload instanceof Buffer) {
msg.payload = "(Buffer) "+msg.payload.toString();
}
if (this.complete) {
if (this.complete == "true") {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg,_path:msg._path});
} else {
if (typeof msg.payload !== "undefined") {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path});
}
}
}
});
}
@ -47,30 +50,21 @@ DebugNode.send = function(msg) {
msg.msg = msg.msg.toString();
}
else if (typeof msg.msg === 'object') {
try {
msg.msg = "(Object) "+JSON.stringify(msg.msg,null,1);
}
catch (err) {
// DCJ - either can just report the circularity...
//msg.msg = "[Error] Can't stringify object with circular reference - see console log.";
// or dump out bits we can... (but things like http are mahoosive objects)
var seen = [];
msg.msg = "(Circular Object) " + JSON.stringify(msg.msg, function(key, value) {
msg.msg = "(Object) " + JSON.stringify(msg.msg, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (seen.indexOf(value) !== -1) { return; }
if (seen.indexOf(value) !== -1) { return "[circular]"; }
seen.push(value);
}
return value;
});
}," ");
seen = null;
}
}
else if (typeof msg.msg === "boolean") msg.msg = "(boolean) "+msg.msg.toString();
else if (msg.msg === 0) msg.msg = "0";
if (msg.msg.length > debuglength) {
msg.msg = msg.msg.substr(0,debuglength) +" ...(more)";
msg.msg = msg.msg.substr(0,debuglength) +" ....";
}
for (var i in DebugNode.activeConnections) {

View File

@ -17,7 +17,7 @@ module.exports = {
uiPort: 1880,
mqttReconnectTime: 15000,
serialReconnectTime: 15000,
debugMaxLength: 500,
debugMaxLength: 1000,
// You can protect the user interface with a userid and password by using the following property
// the password must be an md5 hash eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password')