@edirect/logger
v11.0.43
Published
Advanced logging module for Edirect applications. Provides structured, multi-level logging with support for file output, async configuration, and integration with NestJS and Edirect config modules.
Maintainers
Keywords
Readme
@edirect/logger
Advanced logging module for Edirect applications. Provides structured, multi-level logging with support for file output, async configuration, and integration with NestJS and Edirect config modules.
Features
- Multi-level logging (log, info, warn, error, debug, verbose)
- File and console output
- Async configuration with ConfigService
- Integrates with NestJS
Installation
npm install @edirect/loggerUsage
Register LoggerModule in your AppModule:
import { LoggerModule } from '@edirect/logger';
@Module({
imports: [
LoggerModule.register({
output: 'output',
logs: {
errorFile: 'error_file',
warningFile: 'warning_file',
infoFile: 'info_file',
},
name: 'subscription-service',
}),
],
})
export class AppModule {}Or use async configuration:
import { ConfigService } from '@edirect/config';
@Module({
imports: [
LoggerModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
output: configService.get(Variables.LOGS_OUTPUT),
logs: {
errorFile: configService.get(Variables.LOGS_ERROR_FILE),
warningFile: configService.get(Variables.LOGS_WARNING_FILE),
infoFile: configService.get(Variables.LOGS_INFO_FILE),
},
name: 'subscription-service',
}),
inject: [ConfigService],
}),
],
})
export class AppModule {}Inject LoggerService and use logging methods:
constructor(private loggerService: LoggerService) {}
this.loggerService.log('message', payload);
this.loggerService.info('message', payload);
this.loggerService.warn('message', payload);
this.loggerService.error('message', trace);
this.loggerService.debug('message');
this.loggerService.verbose('message');Inject the LoggerService where needed:
constructor(
private loggerService: LoggerService
) {}Log using the exposed methods:
this.loggerService.log(message: string, payload?: string)
this.loggerService.info(message: string, payload?: string)
this.loggerService.warn(message: string, payload: string)
this.loggerService.error(message: string, trace: string)
this.loggerService.debug(message: string)
this.loggerService.verbose(message: string)