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

debug nodes - show length of strings, buffers or size of arrays

This commit is contained in:
Dave Conway-Jones 2015-08-11 19:39:37 +01:00
parent 5193d7bddb
commit 999b888c54
2 changed files with 7 additions and 7 deletions

View File

@ -201,7 +201,7 @@
msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):''); msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'');
msg.innerHTML = '<span class="debug-message-date">'+ msg.innerHTML = '<span class="debug-message-date">'+
getTimestamp()+'</span>'+ getTimestamp()+'</span>'+
(name?'<span class="debug-message-name">['+name+']':'')+ (name?'<span class="debug-message-name">'+name:'')+
'</span>'; '</span>';
// NOTE: relying on function error to have a "type" that all other msgs don't // NOTE: relying on function error to have a "type" that all other msgs don't
if (o.hasOwnProperty("type") && (o.type === "function")) { if (o.hasOwnProperty("type") && (o.type === "function")) {
@ -212,11 +212,11 @@
errorLvlType = 'warn'; errorLvlType = 'warn';
} }
msg.className = 'debug-message debug-message-level-' + errorLvl; msg.className = 'debug-message debug-message-level-' + errorLvl;
msg.innerHTML += '<span class="debug-message-topic">[function] : (' + errorLvlType + ')</span>'; msg.innerHTML += '<span class="debug-message-topic">function : (' + errorLvlType + ')</span>';
} else { } else {
msg.innerHTML += '<span class="debug-message-topic">'+ msg.innerHTML += '<span class="debug-message-topic">'+
(o.topic?topic+' : ':'')+ (o.topic?topic+' : ':'')+
(o.property?'[msg.'+property+']':'[msg]')+" : "+format+ (o.property?'msg.'+property:'msg')+" : "+format+
'</span>'; '</span>';
} }
@ -284,7 +284,7 @@
.debug-message-topic { .debug-message-topic {
display: block; display: block;
background: #fff; background: #fff;
padding: 1px 5px; padding: 1px;
font-size: 10px; font-size: 10px;
color: #a66; color: #a66;
} }

View File

@ -82,13 +82,13 @@ module.exports = function(RED) {
msg.format = "error"; msg.format = "error";
msg.msg = msg.msg.toString(); msg.msg = msg.msg.toString();
} else if (msg.msg instanceof Buffer) { } else if (msg.msg instanceof Buffer) {
msg.format = "buffer"; msg.format = "buffer ["+msg.msg.length+"]";
msg.msg = msg.msg.toString('hex'); msg.msg = msg.msg.toString('hex');
} else if (typeof msg.msg === 'object') { } else if (typeof msg.msg === 'object') {
var seen = []; var seen = [];
msg.format = "object"; msg.format = "object";
if (util.isArray(msg.msg)) { if (util.isArray(msg.msg)) {
msg.format = "array"; msg.format = "array ["+msg.msg.length+"]";
} }
msg.msg = JSON.stringify(msg.msg, function(key, value) { msg.msg = JSON.stringify(msg.msg, function(key, value) {
if (typeof value === 'object' && value !== null) { if (typeof value === 'object' && value !== null) {
@ -111,7 +111,7 @@ module.exports = function(RED) {
msg.format = (msg.msg === null)?"null":"undefined"; msg.format = (msg.msg === null)?"null":"undefined";
msg.msg = "(undefined)"; msg.msg = "(undefined)";
} else { } else {
msg.format = "string"; msg.format = "string ["+msg.msg.length+"]";
msg.msg = msg.msg; msg.msg = msg.msg;
} }