trtc-electron-sdk
Version:
trtc electron sdk
79 lines (78 loc) • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const trtc_define_1 = require("./trtc_define");
class Logger {
constructor(prefix = 'TRTC') {
this.prefix = `[${prefix}]`;
this.logLevel = trtc_define_1.TRTCLogLevel.TRTCLogLevelInfo;
}
info(...args) {
var _a;
if (this.logLevel <= trtc_define_1.TRTCLogLevel.TRTCLogLevelInfo) {
const param = Array.from(args);
(_a = console.info) === null || _a === void 0 ? void 0 : _a.apply(console, [this.getTime(), this.prefix, ...param]);
}
}
log(...args) {
var _a;
if (this.logLevel <= trtc_define_1.TRTCLogLevel.TRTCLogLevelInfo) {
const param = Array.from(args);
(_a = console.log) === null || _a === void 0 ? void 0 : _a.apply(console, [this.getTime(), this.prefix, ...param]);
}
}
warn(...args) {
var _a;
if (this.logLevel <= trtc_define_1.TRTCLogLevel.TRTCLogLevelWarn) {
const param = Array.from(args);
(_a = console.warn) === null || _a === void 0 ? void 0 : _a.apply(console, [this.getTime(), this.prefix, ...param]);
}
}
error(...args) {
var _a;
if (this.logLevel <= trtc_define_1.TRTCLogLevel.TRTCLogLevelError) {
const param = Array.from(args);
(_a = console.error) === null || _a === void 0 ? void 0 : _a.apply(console, [this.getTime(), this.prefix, ...param]);
}
}
debug(...args) {
var _a;
if (this.logLevel <= trtc_define_1.TRTCLogLevel.TRTCLogLevelDebug) {
const param = Array.from(args);
(_a = console.debug) === null || _a === void 0 ? void 0 : _a.apply(console, [this.getTime(), this.prefix, ...param]);
}
}
setLogLevel(logLevel) {
if (logLevel === trtc_define_1.TRTCLogLevel.TRTCLogLevelNone) {
this.logLevel = trtc_define_1.TRTCLogLevel.TRTCLogLevelError;
}
else {
this.logLevel = logLevel || trtc_define_1.TRTCLogLevel.TRTCLogLevelInfo;
}
}
getTime() {
const date = new Date();
return `${date.toLocaleTimeString('en-US', {
hourCycle: 'h23',
})}.${padMs(date.getMilliseconds())}`;
}
}
exports.Logger = Logger;
function padMs(ms) {
const len = ms.toString().length;
let ret;
switch (len) {
case 1:
ret = `00${ms}`;
break;
case 2:
ret = `0${ms}`;
break;
default:
ret = ms;
break;
}
return ret;
}
const logger = new Logger("TRTC");
exports.default = logger;