0.0.4 • Published 5 years ago

nestjs-woodcutter v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

A Nest module wrapper for woodcutter logger.

Description

Nest Typescript wrapper for woodcutter logger.

Installation

$ npm install -S nestjs-woodcutter woodcutter

Usage

Import WoodcutterModule into the root AppModule and use the forRoot method to configure it.

import { Module } from '@nestjs/common';
import { WoodcutterModule } from 'nestjs-woodcutter';
import { LogLevel } from 'woodcutter';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [WoodcutterModule.forRoot({
    level: LogLevel.INFO,
    timestampFormat: 'YYYY-MM-DD HH:mm:ss'
  })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Then in your bootstrap function:

import { NestFactory } from '@nestjs/core';
import { WOODCUTTER_NEST_PROVIDER } from 'nestjs-woodcutter';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: false,
  });
  app.useLogger(app.get(WOODCUTTER_NEST_PROVIDER));
  await app.listen(3000);
}
bootstrap();

To use the logger, simply instantiate it:

import { Controller, Get, Logger } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  private readonly logger = new Logger(AppController.name);
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    this.logger.debug('Hello controller', this.getHello.name);
    this.logger.error('Cannot say hello');
    this.logger.verbose('Verbose message');
    this.logger.warn('This is a warning');
    return this.appService.getHello();
  }
}

Console output:

woodcutter logs screenshot

Stay in touch

License

nestjs-woodcutter is MIT licensed.