import { ConfigUtil } from "./config-util.class"; const logsEnabledKeyword = 'APP__LOGS__ENABLE'; const logLevelsKeyword = 'APP__LOGS__LEVELS'; const levelColors = { info: "\x1b[32m", warn: "\x1b[33m", error: '\x1b[31m', debug: '\x1b[36m', } export class ConsoleLogger { private static logLevels = ConfigUtil.get(logLevelsKeyword) || ""; public static info(...msg: unknown[]) { this._log('info', ...msg); } public static error(...msg: unknown[]) { this._log('error', ...msg); } public static warn(...msg: unknown[]) { this._log('warn', ...msg); } public static debug(...msg: unknown[]) { this._log('debug', ...msg); } private static _log(level: 'error' | 'info' | 'warn' | 'debug', ...logs: unknown[]) { const enabled = ConfigUtil.get(logsEnabledKeyword); if (!(enabled == 'true' || enabled == '1') || !this.logLevels.includes(level)) return; if (console[level]) console[level](...this._logPrefix(level), ...logs, '\x1b[0m'); } private static _logPrefix(level: string) { return ['\x1b[33m', '[G3] - ', '\x1b[0m', `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()} `, levelColors[level], level.toUpperCase(), ' '] } }