Skip to main content
@snaplog/nest is a high-performance logging and observability integration for NestJS. Register the module once and log from services, controllers, or the framework’s own logger.

Installation

@nestjs/common ^10 || ^11 and rxjs ^7 are peer dependencies.

Quick start

1. Register the module

That is all the setup there is. There are three ways to log, and you can mix them:
  • Automatic — set autoLog: true and every request is logged
  • Manual — call SnapLogService yourself
  • Decorators — tag route handlers and let the interceptor log them

Automatic request logging

With this on, the module registers its request interceptor globally and every incoming request is logged with its method, path, status code, and latency. Decorators and manual SnapLogService calls still work on top. Left out or set to false, which is the default, nothing is logged automatically.

Manual logging

Inject SnapLogService anywhere you need explicit control.

Decorator tracing

The @Log, @Track, @Metrics, and @NoLog decorators attach metadata to a route handler. The interceptor installed by SnapLogModule reads it and logs automatically, so there is no extra registration to do.
Decorators work through an interceptor, so they apply to requests dispatched by the framework — controllers and route handlers. They do not wrap plain injectable methods you call internally. Use SnapLogService for that.

Decorator options

Replace the NestJS logger

SnapLogService implements NestJS’s LoggerService, so it can back the framework’s own bootstrap logging.

Async configuration

Load your key from @nestjs/config with forRootAsync.

Logging

info, audit, and metric take a message and an optional metadata object:
log, warn, and debug take a context string, matching NestJS’s own logger:
error accepts either a trace string or a metadata object:

Configuration

Delivery

Logs are batched and flushed on a timer or once batchSize is reached. A failed send is retried with exponential backoff, and only retryable responses are retried: 408, 429, and any 5xx. Buffered logs are flushed automatically when the module is destroyed, so you do not need to do anything on shutdown.

Exports