Merge branch 'dev' into @feature/issue-5029

This commit is contained in:
Debadutta Panda
2025-04-26 13:26:10 +05:30
committed by GitHub
3 changed files with 19 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ var util = require("util");
var EventEmitter = require("events").EventEmitter;
var i18n = require("./i18n");
const chalk = require("chalk");
var levels = {
off: 1,
@@ -47,6 +48,17 @@ var levelNames = {
99: "metric"
};
var levelColours = {
10: 'red',
20: 'red',
30: 'yellow',
40: 'white',
50: 'cyan',
60: 'gray',
98: 'white',
99: 'white'
};
var logHandlers = [];
var verbose;
@@ -75,28 +87,27 @@ LogHandler.prototype.shouldReportMessage = function(msglevel) {
msglevel <= this.logLevel;
}
// Older versions of Node-RED used the deprecated util.log function.
// With Node.js 22, use of that function causes warnings. So here we
// are replicating the same format output to ensure we don't break any
// log parsing that happens in the real world.
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const utilLog = function (msg) {
const utilLog = function (msg, level) {
const d = new Date();
const time = [
d.getHours().toString().padStart(2, '0'),
d.getMinutes().toString().padStart(2, '0'),
d.getSeconds().toString().padStart(2, '0')
].join(':');
console.log(`${d.getDate()} ${months[d.getMonth()]} ${time} - ${msg}`)
console.log(chalk[levelColours[level] || 'white'](`${d.getDate()} ${months[d.getMonth()]} ${time} - ${msg}`))
}
var consoleLogger = function(msg) {
if (msg.level == log.METRIC || msg.level == log.AUDIT) {
utilLog("["+levelNames[msg.level]+"] "+JSON.stringify(msg));
utilLog("["+levelNames[msg.level]+"] "+JSON.stringify(msg), msg.level);
} else {
if (verbose && msg.msg && msg.msg.stack) {
utilLog("["+levelNames[msg.level]+"] "+(msg.type?"["+msg.type+":"+(msg.name||msg.id)+"] ":"")+msg.msg.stack);
utilLog("["+levelNames[msg.level]+"] "+(msg.type?"["+msg.type+":"+(msg.name||msg.id)+"] ":"")+msg.msg.stack, msg.level);
} else {
var message = msg.msg;
try {
@@ -107,7 +118,7 @@ var consoleLogger = function(msg) {
message = 'Exception trying to log: '+util.inspect(message);
}
utilLog("["+levelNames[msg.level]+"] "+(msg.type?"["+msg.type+":"+(msg.name||msg.id)+"] ":"")+message);
utilLog("["+levelNames[msg.level]+"] "+(msg.type?"["+msg.type+":"+(msg.name||msg.id)+"] ":"")+message, msg.level);
}
}
}

View File

@@ -15,6 +15,7 @@
}
],
"dependencies": {
"chalk": "^4.1.2",
"fs-extra": "11.3.0",
"i18next": "24.2.3",
"json-stringify-safe": "5.0.1",