@donews/nestjs-logger
TypeScript icon, indicating that this package has built-in type declarations

0.10.2 • Public • Published

nest logger module

描述

基于 自我实现伪 json 输出 和 nest内置loggerNest日志 module。

  1. json (伪)
  2. plain 格式输出基于 nest 内置 logger

Install

$ npm i @donews/nestjs-logger

Quick Start

假定一个目录结构

/root
    /src
        app.module.ts

1. 模块导入

import { LOGGER_TYPE, LoggerModule } from '@donews/nestjs-logger';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    LoggerModule.forRoot({
      loggerType: LOGGER_TYPE.JSON_MODEL,
      loggerLevel: 'debug',
      context: 'text',
    }),
  ],
})
export class AppModule {}

2. 增加 asynchronous provider

LoggerModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    loggerType: configService.get('loggerType'),
    loggerLevel: 'debug',
    context: 'text',
  }),
  inject: [ConfigService],
});

3. 使用

import { LoggerInterface, LOGGER } from '@donews/nestjs-logger';
import { Inject, Injectable } from '@nestjs/common';

@Injectable()
class TestService {
  constructor(
    @Inject(LOGGER)
    private readonly loggerService: LoggerInterface,
  ) {}

  say() {
    this.loggerService.info('message', 'context');
    this.loggerService.error('error', 'trace', 'context');
  }
}

4. 日志级别顺序

级别 级别数
error 0
warn 1
log 2
info 2
debug 3
verbose 4

级别从高到低

License

Nest is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @donews/nestjs-logger

Weekly Downloads

10

Version

0.10.2

License

MIT

Unpacked Size

24.6 kB

Total Files

28

Last publish

Collaborators

  • litaixin01
  • stringang