Skip to content

mariomorenodev/nest-response-logger

Repository files navigation

Description

Logger global interceptor library for Nest apps

Installation

$ npm install @mariomorenodev/nest-response-logger

Copy the variables from the .env.example file to the .env file

$ cp .env.example .env

Or add variables to the environment

TZ=UTC

LOG_FILE_PATH=./logs/app.log
LOG_FILE_ENABLED=false

Usage

Add the NestResponseLogger service globally in the main.ts file:

import { NestResponseLoggerService } from '@mariomorenodev/nest-response-logger';

import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: new NestResponseLoggerService(),
  });
  await app.listen(3000);
}
bootstrap();

Add the interceptor globally in the app.module.ts file:

import { LoggerInterceptor } from '@mariomorenodev/nest-response-logger';
import { NestResponseLoggerModule } from '@mariomorenodev/nest-response-logger';

@Module({
  imports: [NestResponseLoggerModule],
  providers: [
    AppService,
    {
      provide: APP_INTERCEPTOR,
      useClass: LoggerInterceptor,
    },
  ],
})

License

Nest response logger MIT licensed.