/* eslint-disable @typescript-eslint/no-explicit-any */ const prefix = 'CSLIB'; export enum LogLevels { VERBOSE = 0, INFO = 1, WARN = 2, ERROR = 3, NONE = 4, } const defaultLogLevel = LogLevels.INFO; let currentLogLevel: LogLevels = defaultLogLevel; export const getLogLevel = (): keyof typeof LogLevels => { return LogLevels[currentLogLevel] as keyof typeof LogLevels; }; export const setLogLevel = (level: keyof typeof LogLevels): void => { if (level in LogLevels) { currentLogLevel = LogLevels[level]; console.info(`${prefix} ℹ️ Info: Log level set to ${level}`); } else { console.warn( `${prefix} ⚠️ Warning: Invalid log level provided, defaulting to ${LogLevels[defaultLogLevel]}` ); currentLogLevel = defaultLogLevel; } }; export const logWithPrefix = ( level: LogLevels, message: string, ...args: any[] ): void => { if (level >= currentLogLevel) { switch (level) { case LogLevels.VERBOSE: console.log(`${prefix} 💬 Verbose: ${message}`, ...args); break; case LogLevels.INFO: console.info(`${prefix} ℹ️ Info: ${message}`, ...args); break; case LogLevels.WARN: console.warn(`${prefix} ⚠️ Warning: ${message}`, ...args); break; case LogLevels.ERROR: console.error(`${prefix} ⛔️ Error: ${message}`, ...args); break; case LogLevels.NONE: // Do nothing for NONE level break; } } };