[mirotalksfu] - add colors, update dep.

هذا الالتزام موجود في:
Miroslav Pejic
2022-09-01 14:11:15 +02:00
الأصل 7e55c06dcb
التزام 088a46c986
2 ملفات معدلة مع 12 إضافات و46 حذوفات

عرض الملف

@@ -1,52 +1,17 @@
'use strict';
const util = require('util');
const colors = require('colors');
colors.enable(); //colors.disable();
const options = {
depth: null,
colors: true,
};
const Log = {
// action
ac: {
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
underscore: '\x1b[4m',
blink: '\x1b[5m',
reverse: '\x1b[7m',
hidden: '\x1b[8m',
},
// Foreground (text) colors
fg: {
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
crimson: '\x1b[38m',
},
// Background colors
bg: {
black: '\x1b[40m',
red: '\x1b[41m',
green: '\x1b[42m',
yellow: '\x1b[43m',
blue: '\x1b[44m',
magenta: '\x1b[45m',
cyan: '\x1b[46m',
white: '\x1b[47m',
crimson: '\x1b[48m',
},
};
module.exports = class Logger {
constructor(appName = 'miroTalkSfu', debugOn = true) {
this.appName = Log.fg.yellow + appName + Log.ac.reset;
this.appName = colors.yellow(appName);
this.debugOn = debugOn;
this.timeStart = Date.now();
this.timeEnd = null;
@@ -72,27 +37,27 @@ module.exports = class Logger {
info(msg, op = '') {
console.info(
'[' + this.getDataTime() + '] [' + this.appName + '] ' + Log.fg.green + msg + Log.ac.reset,
'[' + this.getDataTime() + '] [' + this.appName + '] ' + colors.green(msg),
util.inspect(op, options),
);
}
warn(msg, op = '') {
console.warn(
'[' + this.getDataTime() + '] [' + this.appName + '] ' + Log.fg.yellow + msg + Log.ac.reset,
'[' + this.getDataTime() + '] [' + this.appName + '] ' + colors.yellow(msg),
util.inspect(op, options),
);
}
error(msg, op = '') {
console.error(
'[' + this.getDataTime() + '] [' + this.appName + '] ' + Log.fg.red + msg + Log.ac.reset,
'[' + this.getDataTime() + '] [' + this.appName + '] ' + colors.red(msg),
util.inspect(op, options),
);
}
getDataTime() {
return Log.fg.cyan + new Date().toISOString().replace(/T/, ' ').replace(/Z/, '') + Log.ac.reset;
return colors.cyan(new Date().toISOString().replace(/T/, ' ').replace(/Z/, ''));
}
getFormatTime(ms) {
@@ -111,6 +76,6 @@ module.exports = class Logger {
time = Math.floor((ms / 1000 / 60 / 60) % 24);
type = 'h';
}
return Log.fg.magenta + '+' + time + type + Log.ac.reset;
return colors.magenta('+' + time + type);
}
};