nestjs-woodcutter
v0.0.4
Published
NestJS module for the Woodcutter log package.
Downloads
7
Maintainers
Readme
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:
Stay in touch
- Author - Olivier Schweitzer
- Twitter - @Oli_Schweitzer
License
nestjs-woodcutter is MIT licensed.