a custom logger module enabling structured logging. It supports both JSON and plain text formats. My recommendation is to register it globally once and inject it everywhere!
Example
classLoggerModuleConfigimplementsLoggerModuleOptionsFactory { constructor(privatereadonlyconfigService: ConfigService) {} create() { return { logMode:this.configService.get<LogMode>('LOG_MODE', 'PLAIN_TEXT'), logLevel:this.configService.get<LogLevel>('LOG_LEVEL', 'verbose'), }; } } LoggerModule.registerAsync({ global:true, inject: [ConfigService], useClass:LoggerModuleConfig, }) // Or you can utilize `useFactory`: LoggerModule.registerAsync({ global:true, inject: [ConfigService], useFactory: (configService: ConfigService) => ({ logMode:configService.get<LogMode>('LOG_MODE', 'PLAIN_TEXT'), logLevel:configService.get<LogLevel>('LOG_LEVEL', 'verbose'), }), }) // Or simply: LoggerModule.register({ global:true, logMode:'PLAIN_TEXT', logLevel:'verbose', }) // And to use it in a service app.service.ts @Injectable() exportclassAppService { constructor(privatereadonlylogger: CustomLoggerService) {} helloWorld() { this.logger.verbose('Hello, world!', { context:AppService.name }); } }
Description
a custom logger module enabling structured logging. It supports both JSON and plain text formats. My recommendation is to register it globally once and inject it everywhere!
Example