import pino from 'pino' export enum LoggerType { HTTP = 'http', GAME = 'game', GAME_MASTER = 'gameMaster', APP = 'app', QUEUE = 'queue', COMMAND = 'command', REPOSITORY = 'repository', ENTITY = 'entity', CONSOLE = 'console' } class Logger { private instances: Map> = new Map() private getLogger(type: LoggerType): ReturnType { if (!this.instances.has(type)) { this.instances.set( type, pino({ level: process.env.LOG_LEVEL || 'debug', transport: { target: 'pino/file', options: { destination: `./logs/${type}.log`, mkdir: true } }, formatters: { level: (label) => ({ level: label.toUpperCase() }) }, timestamp: pino.stdTimeFunctions.isoTime, base: null }) ) } return this.instances.get(type)! } type(type: LoggerType) { return { info: (message: string, ...args: any[]) => this.getLogger(type).info(message, ...args), error: (message: string, ...args: any[]) => this.getLogger(type).error(message, ...args), warn: (message: string, ...args: any[]) => this.getLogger(type).warn(message, ...args), debug: (message: string, ...args: any[]) => this.getLogger(type).debug(message, ...args) } } } export default new Logger()