Skip to content

nest-logger 1.0.0-pr254.8

Install from the command line:
Learn more about npm packages
$ npm install @shiftcode/nest-logger@1.0.0-pr254.8
Install via package.json:
"@shiftcode/nest-logger": "1.0.0-pr254.8"

About this version

nest-logger

🎯 Target runtime: es2023 (Node >= 20)

This package provides @shiftcode/logger support for NestJS, allowing you to inject loggers with context-aware naming and configure log transports using the NestJS DI system.

🚀 Features

  • Auto-named logger instances per class
  • Supports multiple log transports
  • Logger service injection for custom logger creation

Usage

1. Set up the module

import { Module } from '@nestjs/common'
import { LoggerModule } from '@shiftcode/nest-logger'
import { LogLevel, NodeConsoleLogTransport, NodeConsoleLogTransportConfig } from '@shiftcode/logger'

@Module({
  imports: [
    // Bind transports (you can bind multiple)
    LoggerModule.withTransports([
      {
        transportClass: NodeConsoleLogTransport,
        config: { logLevel: LogLevel.DEBUG },
      },
    ]),
  ],
})
export class AppModule {}

2. Inject the logger

Option A: Directly inject the logger (auto-named)

import { Injectable, Inject } from '@nestjs/common'
import { Logger } from '@shiftcode/logger'

@Injectable()
class MyService {
  constructor(@Inject(Logger) private logger: Logger) {
    this.logger.info('Initialized!')
  }
}

Option B: Inject the logger service for custom naming

import { Injectable, Inject } from '@nestjs/common'
import { LoggerService } from '@shiftcode/nest-logger'

@Injectable()
class MyService {
  constructor(@Inject(LoggerService) private loggerService: LoggerService) {
    const logger = this.loggerService.getInstance('CustomService')
    logger.debug('Custom-named logger')
  }
}

NestLogger

You can also pass a NestLogger to the NestApplication in a bootstrap function

import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { LoggerService } from '@shiftcode/nest-logger'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  const loggerService = app.get(LoggerService)
  app.useLogger(loggerService.getInstanceNest('MyService'))
  await app.listen(3000)
}

Details


Assets

  • nest-logger-1.0.0-pr254.8.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0