New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aurelle/nestjs-http-logger

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelle/nestjs-http-logger

Logs all requests and responses the API handles, with optional details provided in error scenarios.

  • 0.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

nestjs-http-logger

A simple NestJS module that logs incoming requests and responses, including a configurable amount of details. On error, it can log the payload that is sent to the client in the console to make debugging easier.

Building the package

npm run build 

Utilisation

Simply register the HttpLoggerModule that is exported by this package, passing it the desired configuration:

/* ... */
import { HttpLoggerModule } from '@aurelle/nestjs-http-logger';

@Module({
  imports: [
    HttpLoggerModule.forRoot({
      enableRequestDiscriminator: true,
      sensitiveQueryParams: ['apiKey', 'userToken'],
      shouldLogErrorPayload: true,
      logIpAddress: false,
      printConfigOnApplicationStartup: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Note that none of the options listed above is mandatory. Sane defaults are provided out of the box, so that you can import the module without having to deal with configuration at all.

The list of all the available options is described by the HttpLoggerConfig interface. Here are the defaults:

const defaultConfig: HttpLoggerConfig = {
    sensitiveQueryParams: ['apiKey', 'userToken'],
    enableRequestDiscriminator: false,
    isSensitiveQueryParamCaseSensitive: true,
    logHttpHost: true,
    logIpAddress: true,
    shouldLogErrorPayload: true,
    loggedErrorPayloadMaxSize: '10KB',
    printConfigOnApplicationStartup: false,
    isEnabled: true,
}

Async module registration

You can use the static method HttpModuleLogger.forRootAsync to initialize the configuration asynchronously using Nest's DI system. For example:

/* ... */
import { ConfigModule, ConfigService } from '@nestjs/config';
import { HttpLoggerModule } from '@aurelle/nestjs-http-logger';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    HttpLoggerModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          isEnabled: configService.get<string>('ENABLE_HTTP_LOGGER') === 'true',
          logIpAddress: true,
          printConfigOnApplicationStartup: true,
        };
      },
    }),
    ConfigModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

FAQs

Package last updated on 10 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc