[mirotalksfu] - add time on debug log

هذا الالتزام موجود في:
Miroslav Pejic
2022-08-09 09:16:14 +02:00
الأصل 37e63330fb
التزام 51d3572c43

عرض الملف

@@ -41,10 +41,18 @@ module.exports = class Logger {
constructor(appName = 'miroTalkSfu', debugOn = true) {
this.appName = Log.fg.yellow + appName + Log.ac.reset;
this.debugOn = debugOn;
this.timeStart = performance.now();
this.timeEnd = null;
this.timeElapsedMs = null;
}
debug(msg, op = '') {
if (this.debugOn) console.debug('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
if (this.debugOn) {
this.timeEnd = performance.now();
this.timeElapsedMs = this.getFormatTime(Math.floor(this.timeEnd - this.timeStart));
console.debug('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op, this.timeElapsedMs);
this.timeStart = performance.now();
}
}
log(msg, op = '') {
@@ -66,4 +74,23 @@ module.exports = class Logger {
getDataTime() {
return Log.fg.cyan + new Date().toISOString().replace(/T/, ' ').replace(/Z/, '') + Log.ac.reset;
}
getFormatTime(ms) {
let time = Math.floor(ms);
let type = 'ms';
if (ms >= 1000) {
time = Math.floor((ms / 1000) % 60);
type = 's';
}
if (ms >= 60000) {
time = Math.floor((ms / 1000 / 60) % 60);
type = 'm';
}
if (ms >= 600000) {
time = Math.floor((ms / 1000 / 60 / 60) % 24);
type = 'h';
}
return Log.fg.magenta + '+' + time + type + Log.ac.reset;
}
};