I'm building an app, where i'm creating a logger as a singleton, the problem that i'm facing is that i need to initialise this singleton with data from ENV and i can only do it in a specific place of my code.
Maybe it's not really a singleton since it's returning a different type.
Is it okay to use it like this ? if not do you have any recommandations ?
Thank you.
import CustomLogger, from "./logger"
import ICustomLogger from "./Ilogger"
type LoggerConfig={level:string,format:'json'|'raw'}
class Logger{
private static logger:ICustomLogger;
private static config: LoggerConfig
public static init(config:LoggerConfig){
this.config = config
}
public getInstance():ICustomLogger{
if(!Logger.config){
throw new Error('Config not defined')
}
if(!Logger.logger){
Logger.logger = new CustomLogger(config)
}
return Logger.logger
}
}