@ddboot/log4js
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

@nsboot/logger

Nest Logo

NPM version NPM downloads

Description

log4js-node module for Nest

Installation

$ npm i --save @nsboot/log4js log4js

Quick Start

  • import LoggerModule in your root module
import { Module } from '@nestjs/common';
import { LoggerModule } from '@nsboot/log4js';
@Module({
  imports: [
    LoggerModule.forRootAsync({
      path: 'logs',
      level: 'info',
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
  • use LoggerService in your service
import { Injectable } from '@nestjs/common';
import { LoggerService, InjectLogger, ILogger, Logger } from '@nsboot/log4js';

@Injectable()
export class AppService {
  private logger: Logger;
  //must use @InjectLogger() to inject logger
  constructor(@InjectLogger() private readonly iLogger: ILogger) {
    this.logger = this.iLogger.getLogger(AppService.name);
  }
  getHello(): string {
    this.logger.info('getHello');
    return 'Hello World!';
  }
}
  • or use @Log4j() decorator in your service
import { Injectable } from '@nestjs/common';
import { Logger, Log4j } from '@nsboot/logger';

@Injectable()
export class AppService {
  @Log4j()
  private logger: Logger;

  getHello(): string {
    this.logger.info('getHello');
    return 'Hello World!';
  }
}

Note: @Log4j() decorator will inject Logger instance to your service, so you can use this.logger to log. If you want to use @InjectLogger() decorator, you must use this.iLogger.getLogger() to get Logger instance.

Configuration

  • Config
interface Config {
  path?: string;
  level?: string;
  // file name
  name?: string;
  // console show log
  console?: boolean;
}

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

License

@nsboot/logger is MIT licensed.

Readme

Keywords

Package Sidebar

Install

npm i @ddboot/log4js

Weekly Downloads

4

Version

1.1.3

License

MIT

Unpacked Size

21.6 kB

Total Files

28

Last publish

Collaborators

  • charlesmaxwellyoung