UNPKG

@senx/warp10

Version:

Warp 10 NodeJS library

81 lines (80 loc) 2.61 kB
"use strict"; /* * Copyright 2023 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.LEVEL = exports.Logger = void 0; /* eslint-disable no-console */ class Logger { constructor(className, isDebug = false, silent = false) { this.isDebug = false; this.silent = false; this.className = className.name; this.isDebug = isDebug; this.silent = silent; } log(level, methods, args) { if (!this.silent) { 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); } } exports.Logger = Logger; var LEVEL; (function (LEVEL) { LEVEL[LEVEL["DEBUG"] = 0] = "DEBUG"; LEVEL[LEVEL["ERROR"] = 1] = "ERROR"; LEVEL[LEVEL["WARN"] = 2] = "WARN"; LEVEL[LEVEL["INFO"] = 3] = "INFO"; })(LEVEL || (exports.LEVEL = LEVEL = {}));