UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

109 lines (108 loc) 3.76 kB
import GirafeSingleton from '../../base/GirafeSingleton'; import ConfigManager from '../configuration/configmanager'; export default class LogManager extends GirafeSingleton { constructor(type) { super(type); Object.defineProperty(this, "configManager", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "defaultDebug", { enumerable: true, configurable: true, writable: true, value: console.debug }); Object.defineProperty(this, "defaultLog", { enumerable: true, configurable: true, writable: true, value: console.log }); Object.defineProperty(this, "defaultInfo", { enumerable: true, configurable: true, writable: true, value: console.info }); Object.defineProperty(this, "defaultWarn", { enumerable: true, configurable: true, writable: true, value: console.warn }); Object.defineProperty(this, "defaultError", { enumerable: true, configurable: true, writable: true, value: console.error }); this.configManager = ConfigManager.getInstance(); } async initLogging() { await this.configManager.loadConfig(); console.debug = this.debug.bind(this); console.log = this.log.bind(this); console.info = this.info.bind(this); console.warn = this.warn.bind(this); console.error = this.error.bind(this); } /** * Write log to output if the current loglevel is debug, info, warn or error * @returns true if the log was written, false instead */ debug(message, ...optionalParams) { if (this.configManager.Config.general.logLevel === 'debug') { this.defaultDebug(message, ...optionalParams); return true; } return false; } /** * Write log to output if the current loglevel is info, warn or error * @returns true if the log was written, false instead */ log(message, ...optionalParams) { if (this.configManager.Config.general.logLevel === 'debug' || this.configManager.Config.general.logLevel === 'info') { this.defaultLog(message, ...optionalParams); return true; } return false; } /** * Write log to output if the current loglevel is info, warn or error * @returns true if the log was written, false instead */ info(message, ...optionalParams) { if (this.configManager.Config.general.logLevel === 'debug' || this.configManager.Config.general.logLevel === 'info') { this.defaultInfo(message, ...optionalParams); return true; } return false; } /** * Write log to output if the current loglevel is warn or error * @returns true if the log was written, false instead */ warn(message, ...optionalParams) { if (this.configManager.Config.general.logLevel === 'debug' || this.configManager.Config.general.logLevel === 'info' || this.configManager.Config.general.logLevel === 'warn') { this.defaultWarn(message, ...optionalParams); return true; } return false; } /** * Write log to output if the current loglevel is error * @returns true if the log was written, false instead */ error(message, ...optionalParams) { this.defaultError(message, ...optionalParams); return true; } }