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

@bluealba/nestjs-pino

v1.0.0

Published

NestJS pino based logger module including pino-http

Readme

@bluealba/nestjs-pino

A NestJS logger module built on top of nestjs-pino with opinionated defaults for production-ready logging using Pino and pino-http.

Features

  • High-performance JSON logging with Pino
  • HTTP request/response logging with pino-http
  • Automatic logger context based on the injecting class
  • Buffered asynchronous logging for optimal performance
  • Automatic redaction of sensitive headers
  • Global module - import once, use everywhere

Installation

npm install @bluealba/nestjs-pino

Usage

1. Import the LoggerModule

Import LoggerModule in your application's root module:

import { Module } from '@nestjs/common';
import { LoggerModule } from '@bluealba/nestjs-pino';

@Module({
  imports: [LoggerModule],
  // ...
})
export class AppModule {}

Since LoggerModule is a global module, you only need to import it once in your root module. It will be available throughout your entire application.

2. Inject the Logger

Important: The logger must be injected via dependency injection. Inject the Logger into any service, controller, or provider:

import { Injectable } from '@nestjs/common';
import { Logger } from '@bluealba/nestjs-pino';

@Injectable()
export class UserService {
  constructor(private readonly logger: Logger) {}

  async findUser(id: string) {
    this.logger.info({ userId: id }, 'Finding user');
    // ...
  }
}

3. Automatic Context Setting

The logger context is automatically set based on the class where it's injected. You do not need to call setContext() manually.

@Injectable()
export class UserService {
  constructor(private readonly logger: Logger) {
    // Context is automatically set to "UserService"
    // No need to call: this.logger.setContext('UserService')
  }

  createUser(data: CreateUserDto) {
    // Logs will include: "context": "UserService"
    this.logger.info({ data }, 'Creating user');
  }
}

The context is derived from the class constructor name, making it easy to identify which part of your application generated each log entry.

4. Logging Methods

The logger provides all standard Pino logging methods:

this.logger.trace('Trace message');
this.logger.debug({ data }, 'Debug message');
this.logger.info({ userId: '123' }, 'Info message');
this.logger.warn('Warning message');
this.logger.error({ err }, 'Error message');
this.logger.fatal('Fatal message');

The log() method is also available and maps to info():

this.logger.log('This is an info message');

Default Configuration

This library comes with production-ready defaults:

Logging Performance

  • Asynchronous logging: Logs are written asynchronously to avoid blocking the event loop
  • Buffering:
    • Minimum buffer length: 512 bytes
    • Maximum buffer length: 128 KB
    • Maximum write size: 128 KB
  • Periodic flush: Every 1000ms (1 second)

Security

Sensitive HTTP headers are automatically redacted from logs:

  • req.headers.authorization
  • req.headers.cookie

Request Serialization

HTTP requests are logged with the following fields:

  • id: Request ID
  • method: HTTP method
  • url: Request URL
  • headers: Request headers (with sensitive data redacted)
  • remoteAddress: Client IP address
  • remotePort: Client port or X-Forwarded-Port header

Timestamp Format

Logs include a Unix timestamp (milliseconds since epoch):

{
  "level": 30,
  "timestamp": 1705761234567,
  "context": "UserService",
  "msg": "User created"
}

Why Use This Library?

This library wraps nestjs-pino with sensible defaults so you don't have to configure:

  • Buffering and async logging for performance
  • Security best practices (header redaction)
  • Structured request logging
  • Context management

It allows you to focus on writing logs instead of configuring the logger.

License

PolyForm-Noncommercial-1.0.0