You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

nestjs-cls-logger

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-cls-logger

nestjs cls logger npm

1.1.4
latest
Source
npmnpm
Version published
Weekly downloads
446
5.69%
Maintainers
1
Weekly downloads
 
Created
Source

NestJS CLS Logger

Thanks very much for the excellent content below:

  • Logging on NestJS like a Pro with Correlation IDs, Log Aggregation, Winston, Morgan and more

  • nestjs-cls

This is a simplified version of NestJS CLS Logger. Implementing console logging functionality while tracing the processing flow through Correlation IDs.

Also capable of sending 'fatal' and 'emergency' level information to a specified Slack webhook in the production environment

Install

npm i nestjs-cls-logger

Detailed usage examples

  • Create a sample nestjs app
# install nest cli
npm i -g @nestjs/cli

# create sample app
nest new sample-app
cd sample-app
  • Install this npm
npm i nestjs-cls-logger
  • Import LoggerModule into AppModule
// ./src/app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { NestJsClsLoggerModule } from 'nestjs-cls-logger';

@Module({
  imports: [NestJsClsLoggerModule.forRoot({ tag: 'app.sample' })],
  // imports: [NestJsClsLoggerModule.forRoot({ tag: 'app.sample', overrideConsole: true })]
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
  • Regist logger at bootstrap()
// ./src/main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestjsLoggerServiceAdapter } from 'nestjs-cls-logger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { bufferLogs: true });
  app.useLogger(app.get(NestjsLoggerServiceAdapter));
  await app.listen(3000);
}
bootstrap();
  • Use Logger in Service
// ./src/app.service.ts

import { Injectable } from '@nestjs/common';
import { LoggerService } from 'nestjs-cls-logger';

@Injectable()
export class AppService {
  constructor(private readonly logger: LoggerService) {}

  getHello(): string {
    this.logger.debug('start!');
    return 'Hello World!';
  }
}
npm run start:dev
  • Console should have the following output:

console

Release Notes

1.1.3

  • Bugfix: correct output of Props

1.1.2

  • Disable colorization by default
  • Remove last newline of morgan message

1.1.0

  • Option to override console

1.0.0

  • Initial release.

Keywords

nestjs

FAQs

Package last updated on 02 May 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.