npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ambak/nest-logger

v1.1.0

Published

Structured logging for NestJS applications

Readme

@ambak/nest-logger

Structured logging for NestJS applications with request tracing, sensitive data sanitization, and optional GraphQL-aware request logging.

Installation

npm install @ambak/nest-logger pino pino-pretty safe-stable-stringify

Required peer dependencies:

  • @nestjs/common
  • @nestjs/core
  • reflect-metadata
  • rxjs

Optional GraphQL support is enabled automatically when @nestjs/graphql is installed.

Quick Start

import { Module } from '@nestjs/common';
import { LoggerModule } from '@ambak/nest-logger';

@Module({
  imports: [
    LoggerModule.forRoot({
      PROJECT_ID: 'ambak-prod',
      SERVICE_NAME: 'payments-api',
      LOG_LEVEL: 'info',
      LOG_FORMAT: 'json',
      LOG_TYPE: 'gcp'
    })
  ]
})
export class AppModule {}

The module attaches a global interceptor and exception filter for structured request, response, and error logs unless LOG_REGISTER is set to 0 or 1.

Usage

Inject a contextual child logger into providers:

import { Injectable } from '@nestjs/common';
import { InjectLogger, BaseLoggerService } from '@ambak/nest-logger';

@Injectable()
export class UsersService {
  @InjectLogger()
  private readonly logger!: BaseLoggerService;

  findAll() {
    this.logger.info({ message: 'Fetching users' });
    return [];
  }
}

Log method execution:

import { Injectable } from '@nestjs/common';
import { InjectLogger, LogMethod, BaseLoggerService } from '@ambak/nest-logger';

@Injectable()
export class PaymentsService {
  @InjectLogger()
  private readonly logger!: BaseLoggerService;

  @LogMethod({ includeArgs: true, includeResult: true })
  async createPayment(payload: Record<string, unknown>) {
    return { ok: true, payload };
  }
}

Access the current request context inside a controller:

import { Controller, Get } from '@nestjs/common';
import { GetRequestContext } from '@ambak/nest-logger';
import { RequestContext } from '@ambak/nest-logger';

@Controller('health')
export class HealthController {
  @Get()
  get(@GetRequestContext() context: RequestContext | undefined) {
    return { requestId: context?.requestId };
  }
}

Configuration

| Option | Required | Description | | --- | --- | --- | | PROJECT_ID | Yes | Project or account identifier included in log records. | | SERVICE_NAME | Yes | Service name used in logger metadata and resource fields. | | LOG_LEVEL | No | Pino log level such as trace, debug, info, warn, error, or fatal. | | LOG_FORMAT | No | json or pretty. Defaults to JSON output. | | LOG_TYPE | No | gcp or aws. Controls log formatting conventions. | | LOGGER_NAME | No | Overrides the logger name sent in the base log payload. | | LOG_REGISTER | No | 0 disables logs, 1 uses raw console output, 2-5 use structured logging. | | LOGGER_SENSITIVE_FIELDS | No | Comma-separated request/response fields to redact in addition to built-ins. | | LOGGER_SENSITIVE_HEADERS | No | Comma-separated headers to redact in addition to built-ins. | | includeResource | No | Adds resource metadata to formatted output when supported. | | includeTrace | No | Adds trace correlation metadata when available. |

Built-in exclusions skip noisy endpoints such as /health, /metrics, and /ready.

GraphQL Logging

When @nestjs/graphql is installed, GraphQL requests are logged automatically and include:

  • operation type
  • operation name
  • resolver field name
  • request variables and response payloads

From v1.1.0, GraphQL response and error logs also include operation metadata consistently.

Notes

  • Sensitive headers such as authorization, cookie, x-api-key, and gateway-services are redacted by default.
  • Large payloads, base64 blobs, image URLs, and common PII patterns are sanitized before logging.
  • The package publishes compiled files from dist/ plus this README.