Code Monkey home page Code Monkey logo

ddboot-logger's Introduction

@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.

ddboot-logger's People

Contributors

charlesmyoung avatar tansincosy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.