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

Add some colour smarts to debug status

This commit is contained in:
Dave Conway-Jones 2020-05-15 16:06:34 +01:00
parent 184d928cf7
commit 88d4d306f3
No known key found for this signature in database
GPG Key ID: 302A6725C594817F

View File

@ -2,7 +2,7 @@ module.exports = function(RED) {
"use strict"; "use strict";
var util = require("util"); var util = require("util");
var events = require("events"); var events = require("events");
var path = require("path"); //var path = require("path");
var debuglength = RED.settings.debugMaxLength || 1000; var debuglength = RED.settings.debugMaxLength || 1000;
var useColors = RED.settings.debugUseColors || false; var useColors = RED.settings.debugUseColors || false;
util.inspect.styles.boolean = "red"; util.inspect.styles.boolean = "red";
@ -20,7 +20,6 @@ module.exports = function(RED) {
this.statusVal = n.statusVal || this.complete; this.statusVal = n.statusVal || this.complete;
this.tosidebar = n.tosidebar; this.tosidebar = n.tosidebar;
if (this.tosidebar === undefined) { this.tosidebar = true; } if (this.tosidebar === undefined) { this.tosidebar = true; }
this.severity = n.severity || 40;
this.active = (n.active === null || typeof n.active === "undefined") || n.active; this.active = (n.active === null || typeof n.active === "undefined") || n.active;
if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); } if (this.tostatus) { this.status({fill:"grey", shape:"ring"}); }
else { this.status({}); } else { this.status({}); }
@ -28,26 +27,6 @@ module.exports = function(RED) {
var statExpression = hasStatExpression ? n.statusVal : null; var statExpression = hasStatExpression ? n.statusVal : null;
var node = this; var node = this;
var levels = {
off: 1,
fatal: 10,
error: 20,
warn: 30,
info: 40,
debug: 50,
trace: 60,
audit: 98,
metric: 99
};
var colors = {
"0": "grey",
"10": "grey",
"20": "red",
"30": "yellow",
"40": "grey",
"50": "green",
"60": "blue"
};
var preparedEditExpression = null; var preparedEditExpression = null;
var preparedStatExpression = null; var preparedStatExpression = null;
if (editExpression) { if (editExpression) {
@ -111,9 +90,15 @@ module.exports = function(RED) {
if (err) { node.error(err); return; } if (err) { node.error(err); return; }
var output = debugMsg.msg; var output = debugMsg.msg;
var st = (typeof output === 'string') ? output : util.inspect(output); var st = (typeof output === 'string') ? output : util.inspect(output);
var severity = msg.errorlevel || node.severity;
if (st.length > 32) { st = st.substr(0,32) + "..."; } if (st.length > 32) { st = st.substr(0,32) + "..."; }
node.status({fill:colors[severity] || "grey", shape:"dot", text:st}); var fill = "grey";
var shape = "dot";
if (node.statusVal === "error.message" && msg.hasOwnProperty("error")) { fill = "red"; }
if (node.statusVal === "status.text" && msg.hasOwnProperty("status")) {
if (msg.status.hasOwnProperty("fill")) { fill = msg.status.fill; }
if (msg.status.hasOwnProperty("shape")) { shape = msg.status.shape; }
}
node.status({fill:fill, shape:shape, text:st});
}); });
} }