@senx/discovery-widgets
Version:
Discovery Widgets Elements
74 lines (73 loc) • 2.31 kB
JavaScript
/*
* Copyright 2022-2025 SenX S.A.S.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class Logger {
constructor(className, isDebug = false) {
this.isDebug = false;
this.className = className.name;
this.isDebug = isDebug;
}
log(level, methods, args) {
let logChain = [];
logChain.push(`[${new Date().toISOString()} - [${this.className}] ${methods.join(' - ')}`);
logChain = logChain.concat(args);
switch (level) {
case LEVEL.DEBUG: {
if (this.isDebug) {
console.debug(...logChain);
}
break;
}
case LEVEL.ERROR: {
console.error(...logChain);
break;
}
case LEVEL.INFO: {
console.log(...logChain);
break;
}
case LEVEL.WARN: {
console.warn(...logChain);
break;
}
default: {
if (this.isDebug) {
console.log(...logChain);
}
}
}
}
debug(methods, ...args) {
this.log(LEVEL.DEBUG, methods, args);
}
error(methods, ...args) {
this.log(LEVEL.ERROR, methods, args);
}
warn(methods, ...args) {
this.log(LEVEL.WARN, methods, args);
}
info(methods, ...args) {
this.log(LEVEL.INFO, methods, args);
}
}
export var LEVEL;
(function (LEVEL) {
// eslint-disable-next-line no-unused-vars
LEVEL[LEVEL["DEBUG"] = 0] = "DEBUG";
LEVEL[LEVEL["ERROR"] = 1] = "ERROR";
LEVEL[LEVEL["WARN"] = 2] = "WARN";
LEVEL[LEVEL["INFO"] = 3] = "INFO";
})(LEVEL || (LEVEL = {}));
//# sourceMappingURL=logger.js.map