type TSessions = Map class PluggerLog { static sessions: TSessions = new Map() static activeSession: number static loggingTag = 'Plugger::JS' static isSilent = false static timeStampOnly = false public static init() { PluggerLog.activeSession = +new Date() PluggerLog.sessions.set(PluggerLog.activeSession, []) } public static stop() { PluggerLog.activeSession = 0 } public static silent() { PluggerLog.isSilent = true } public static print(...stuff: any[]) { const statement = PluggerLog._prepareForLogging(stuff) if (!PluggerLog.isSilent) console.log(statement, ...stuff) } public static error(...stuff: any[]) { const statement = PluggerLog._prepareForLogging(stuff) if (!PluggerLog.isSilent) { console.log(statement, ...stuff) } } public static add(...stuff: any[]) { PluggerLog._prepareForLogging(stuff) } public static retrieve() { return PluggerLog.sessions } private static _prepareForLogging(stuff: any[]): string { if (!PluggerLog.activeSession) PluggerLog.init() const time = PluggerLog.timeStampOnly ? +new Date() : new Date().toLocaleTimeString() const statement = time + ' ' + PluggerLog.loggingTag + '::' PluggerLog.sessions.get(PluggerLog.activeSession)?.push({statement, stuff}) return statement } } export default PluggerLog