@andrei-tatar/node-red-contrib-nibetcp
Version:
Node-red integration for Nibe S series heatpumps using modbus over TCP
48 lines (47 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.Logger = void 0;
class Logger {
constructor(scopes = []) {
this.scopes = scopes;
}
scope(scope) {
return new Logger([...this.scopes, scope]);
}
log(level, msg, ...args) {
const scopes = this.scopes.map((s) => `[${s}]`).join("");
const coloredText = this.color(level, `[${level.toUpperCase()}]${scopes}`);
const stamp = (new Date().getTime() - Logger.start)
.toString()
.padStart(8, " ");
console.log(`[${stamp}]${coloredText} ${msg}`, ...args);
}
info(msg, ...args) {
this.log("info", msg, ...args);
}
error(msg, ...args) {
this.log("error", msg, ...args);
}
trace(msg, ...args) {
this.log("trace", msg, ...args);
}
warn(msg, ...args) {
this.log("warn", msg, ...args);
}
debug(msg, ...args) {
this.log("debug", msg, ...args);
}
color(level, text) {
const MAP = new Map([
["error", "31m"],
["info", "36m"],
["trace", "32m"],
["warn", "33m"],
["debug", "35m"],
]);
return `\x1b[${MAP.get(level)}${text}\x1b[0m`;
}
}
exports.Logger = Logger;
Logger.start = new Date().getTime();
exports.logger = null; // new Logger();