nestjs-backend-common
    Preparing search index...

    Class LoggerModule

    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!

    class LoggerModuleConfig implements LoggerModuleOptionsFactory {
    constructor(private readonly configService: 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()
    export class AppService {
    constructor(private readonly logger: CustomLoggerService) {}
    helloWorld() {
    this.logger.verbose('Hello, world!', { context: AppService.name });
    }
    }

    Hierarchy

    • ConfigurableModuleClass
      • LoggerModule

    Indexable

    • [key: string]: any
    Index

    Constructors

    Methods

    Constructors

    • Returns LoggerModule

    Methods

    • Parameters

      • options: ConfigurableModuleAsyncOptions<LoggerModuleOptions, "create"> & Partial<
            CommonModuleOptions,
        >

      Returns DynamicModule