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

@urfav/smart-logger

v0.1.0

Published

Configurable Winston logger for NestJS with sensitive-data masking and pluggable request-context enrichment.

Readme

@urfav/smart-logger

A configurable Winston logger for NestJS with built-in sensitive-data masking and pluggable request-context enrichment.

It is the standalone, framework-agnostic evolution of the in-app logger.util helper: every coupling to a specific app (env schema, CLS store shape, hard-coded filenames, process.env reads) is now an injected option.

Features

  • Sensitive-data masking — redacts configured keys recursively through objects, arrays, and stringified/inline JSON, with circular-reference safety.
  • Pluggable context enrichment — inject a traceId (or any fields) from a request-scoped store via a LogContextProvider. A ready-made nestjs-cls adapter ships in the box.
  • Optional transports, lazily loadedwinston-daily-rotate-file, winston-transport-sentry-node, and nest-winston's console formatter are optional peer dependencies; you only install what you use.
  • First-class NestJS integrationSmartLoggerModule.forRoot / forRootAsync, plus a SmartLoggerService that implements NestJS's LoggerService. The raw winston instance is also exported for WinstonModule.createLogger({ instance })-style wiring.

Installation

yarn add @urfav/smart-logger winston @nestjs/common reflect-metadata
# install only the optional transports you actually use:
yarn add nest-winston                    # nestLike console formatting
yarn add winston-daily-rotate-file       # rotating file logs
yarn add winston-transport-sentry-node   # Sentry error reporting

Quick start (NestJS)

import { Module } from '@nestjs/common';
import { ClsService } from 'nestjs-cls';
import { SmartLoggerModule, ClsContextProvider } from '@urfav/smart-logger';

@Module({
  imports: [
    SmartLoggerModule.forRootAsync({
      isGlobal: true,
      inject: [ClsService],
      useFactory: (cls: ClsService) => ({
        appName: process.env.APP_NAME,
        sensitiveKeys: process.env.LOGGER_SENSITIVE_KEYS,
        contextProvider: new ClsContextProvider(cls, ['traceId']),
        console: process.env.NODE_ENV !== 'prod' ? { nestLike: true } : false,
        file: process.env.NODE_ENV === 'prod' ? { filename: 'logs/gateway-%DATE%.log' } : undefined,
        sentry: process.env.SENTRY_DSN ? { dsn: process.env.SENTRY_DSN, environment: process.env.NODE_ENV } : undefined,
      }),
    }),
  ],
})
export class AppModule {}

Then route NestJS's own logs through it:

import { SmartLoggerService } from '@urfav/smart-logger';

const app = await NestFactory.create(AppModule, { bufferLogs: true });
app.useLogger(app.get(SmartLoggerService));

Bootstrap usage (without DI)

The factory works standalone — useful at main.ts before the DI container exists, mirroring the original WinstonModule.createLogger({ instance }) pattern:

import { WinstonModule } from 'nest-winston';
import { createSmartLogger, ClsContextProvider } from '@urfav/smart-logger';

const app = await NestFactory.create(AppModule, {
  logger: WinstonModule.createLogger({
    instance: createSmartLogger({
      appName: process.env.APP_NAME,
      sensitiveKeys: process.env.LOGGER_SENSITIVE_KEYS,
      contextProvider: new ClsContextProvider(cls),
    }),
  }),
});

Configuration

SmartLoggerOptions:

| Option | Type | Default | Notes | | ----------------- | ----------------------------------------------- | ----------------------- | --------------------------------------------------------------------- | | appName | string | — | Used as the nestLike console label. | | level | string | 'debug' | Minimum level to emit. | | sensitiveKeys | string \| string[] | [] | Comma-separated string or array of keys to redact. | | timestampFormat | string | 'YYYY-MM-DD HH:mm:ss' | Winston timestamp format. | | levelConfig | { levels; colors } | custom 8-level set | Override the level/colour map. | | contextProvider | LogContextProvider \| () => Record | — | Enriches every record (e.g. traceId). | | console | ConsoleTransportConfig \| boolean | enabled (nestLike) | false to disable; { nestLike: false } for a plain console. | | file | FileTransportConfig | disabled | Enables a daily-rotating JSON file transport. | | sentry | SentryTransportConfig | disabled | Enables the Sentry transport (defaults to level: 'error'). | | exitOnError | boolean | false | Passed through to winston. |

Transports are driven by which option blocks are present — there is no implicit env switch. The consumer decides what to enable for each environment.

Custom context providers

ClsContextProvider accepts anything with a get(key) method, so it works with a nestjs-cls ClsService without this package depending on nestjs-cls. For other stores, implement the interface directly:

import { LogContextProvider } from '@urfav/smart-logger';

class RequestContextProvider implements LogContextProvider {
  resolve(): Record<string, unknown> {
    return { traceId: currentTrace(), tenantId: currentTenant() };
  }
}

Development

yarn install
yarn build      # tsc -> dist/
yarn test       # jest
yarn test:cov   # coverage

License

MIT © Uchenna Nnochirionye