Skip to content

Commit deff93f

Browse files
committed
Simplify debug node message processing.
Make processing more consistent irrespective of complete flag. Avoid processing when node is inactive. Avoid duplicate code.
1 parent 78edf89 commit deff93f

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

nodes/core/core/58-debug.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module.exports = function(RED) {
3535
if (this.console == "true") {
3636
node.log("\n"+util.inspect(msg, {colors:useColors, depth:10}));
3737
}
38-
if (msg.payload instanceof Buffer) { msg.payload = "(Buffer) "+msg.payload.toString('hex'); }
3938
if (this.active) {
4039
sendDebug({id:this.id,name:this.name,topic:msg.topic,msg:msg,_path:msg._path});
4140
}
@@ -48,8 +47,6 @@ module.exports = function(RED) {
4847
else if (typeof msg.payload === "object") { node.log("\n"+util.inspect(msg.payload, {colors:useColors, depth:10})); }
4948
else { node.log(util.inspect(msg.payload, {colors:useColors})); }
5049
}
51-
if (typeof msg.payload == "undefined") { msg.payload = "(undefined)"; }
52-
if (msg.payload instanceof Buffer) { msg.payload = "(Buffer) "+msg.payload.toString('hex'); }
5350
if (this.active) {
5451
sendDebug({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path});
5552
}
@@ -62,6 +59,8 @@ module.exports = function(RED) {
6259
function sendDebug(msg) {
6360
if (msg.msg instanceof Error) {
6461
msg.msg = msg.msg.toString();
62+
} else if (msg.msg instanceof Buffer) {
63+
msg.msg = "(Buffer) "+msg.msg.toString('hex');
6564
} else if (typeof msg.msg === 'object') {
6665
var seen = [];
6766
var ty = "(Object) ";
@@ -79,7 +78,7 @@ module.exports = function(RED) {
7978
} else if (msg.msg === 0) {
8079
msg.msg = "0";
8180
} else if (msg.msg == null) {
82-
msg.msg = "[undefined]";
81+
msg.msg = "(undefined)";
8382
}
8483

8584
if (msg.msg.length > debuglength) {

0 commit comments

Comments
 (0)