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

Debug output should use overridden toString method if set

Closes #690
This commit is contained in:
Nick O'Leary 2015-09-25 23:32:33 +01:00
parent 4a0222bd1c
commit 8d73f927db

View File

@ -87,16 +87,22 @@ module.exports = function(RED) {
} else if (typeof msg.msg === 'object') {
var seen = [];
msg.format = "object";
if (util.isArray(msg.msg)) {
msg.format = "array ["+msg.msg.length+"]";
}
msg.msg = JSON.stringify(msg.msg, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (seen.indexOf(value) !== -1) { return "[circular]"; }
seen.push(value);
var isArray = util.isArray(msg.msg);
if (!isArray && msg.msg.toString !== Object.prototype.toString) {
msg.format = msg.msg.constructor.name || "object";
msg.msg = msg.msg.toString();
} else {
if (isArray) {
msg.format = "array ["+msg.msg.length+"]";
}
return value;
}," ");
msg.msg = JSON.stringify(msg.msg, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (seen.indexOf(value) !== -1) { return "[circular]"; }
seen.push(value);
}
return value;
}," ");
}
seen = null;
} else if (typeof msg.msg === "boolean") {
msg.format = "boolean";