UNPKG

fcr-core

Version:

Core APIs for building online scenes

48 lines 1.59 kB
import { LoggerManager } from '../imports'; export class FcrCoreLoggerManagerHolder { static instance = null; static isDestroying = false; static label = 'fcr-core'; static initialize(opts) { if (this.instance && !this.isDestroying) { console.warn(`${this.label} LoggerManager is already initialized. Reinitializing...`); } this.destroy(); this.instance = new LoggerManager({ label: this.label, maxSize: opts.maxSize }); } static getInstance() { if (!this.instance) { throw new Error(`LoggerManager is not initialized. Call ${this.label} LoggerManager.initialize() first.`); } return this.instance; } static createLogger(opts) { return this.getInstance().createLogger(opts); } static getLogger() { return this.getInstance().getLogger(); } static generateLogObserver(logger, callbackMethods) { return this.getInstance().generateLogObserver(logger, callbackMethods); } static destroy() { if (this.instance && !this.isDestroying) { this.isDestroying = true; try { this.instance.release(); } finally { this.instance = null; this.isDestroying = false; } } } static isInitialized() { return this.instance !== null; } } export const getLogger = FcrCoreLoggerManagerHolder.getLogger.bind(FcrCoreLoggerManagerHolder); export const createLogger = FcrCoreLoggerManagerHolder.createLogger.bind(FcrCoreLoggerManagerHolder); export const generateLogObserver = FcrCoreLoggerManagerHolder.generateLogObserver.bind(FcrCoreLoggerManagerHolder);