Logger module for Nest - modern, fast, powerful node.js web framework (@hhnest)


Keywords
nestjs, logger
License
MIT
Install
npm install @hhnest/logger@1.1.3

Documentation

Nest Logo

@hhnest/logger

Build codecov

Description

A logger module for Nest.

Wrap standard nestjs logger and add API for set level to runtime globally or for each logger

Installation

$ npm install @hhnest/logger --save

Import module in your the app

import {LoggerModule} from '@hhnest/logger';
import { LogLevel } from '@nestjs/common';

const initialLevels: LogLevel[] = ['error', 'warn', 'log', 'debug'];
...
@Module({
  imports: [
    HttpModule,
    LoggerModule.forRoot(initialLevels),
    // or 
    LoggerModule.forRoot(), // ['error', 'warn', 'log']
    ...
 ],
  controllers: [...],
  providers: [...],
})
export class AppModule {
  ...
}

Use

import { Log } from '@hhnest/logger';

@Injectable()
export class MyService {

  constructor(
    @Log(MyService.name) private readonly logger
  ) {
  }
  method() {
    this.logger.error(`message`)
  }
  ...
}

API

Return global logger levels

/logger

Change levels of logger globally

/logger/level/(error|warn|log|debug|verbose|reset)

If specific logger has been set to another level, level of it doesn't change.


Return specific logger levels

/logger/context/SpecificLogger

Change level of specific logger

/logger/context/SpecificLogger/level/(error|warn|log|debug|verbose|reset)

If reset, remove specific and use global levels for it.


License

@hhnest/logger is MIT licensed.