UNPKG

pm2-prom-module

Version:

PM2 module to help collect applications statistic and send it to Prometheus server

44 lines (43 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLogger = exports.initLogger = void 0; class SimpleLogger { constructor(isDebug = false) { this.isDebug = false; this.isDebug = isDebug; } debug(message) { if (this.isDebug) { const value = `DEBUG: ${message}`; this.log(value); } } error(message) { const value = `ERROR: ${message}`; this.logError(value); } info(message) { const value = `INFO: ${message}`; this.log(value); } log(message) { console.log(message); } logError(message) { console.error(message); } } let loggerInstance; const initLogger = ({ isDebug }) => { if (!loggerInstance) { loggerInstance = new SimpleLogger(isDebug); } }; exports.initLogger = initLogger; const getLogger = () => { if (!loggerInstance) { loggerInstance = new SimpleLogger(); } return loggerInstance; }; exports.getLogger = getLogger;