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

2.1.0 • Public • Published

Description

A logger module for Nestjs, built on top of node-bunyan.

Features

  • A gloabl bunyan logger provider can be used in the controllers/services.
  • Automatically log request/response with request-id, timestamp, status-code, etc.

Usage

Installation

Yarn

yarn add @wiredcraft/nestjs-bunayn-logger

NPM

npm install @wiredcraft/nestjs-bunayn-logger --save

Integration

  1. Import LoggerModule in the root App module, this provides initialized bunyan logger instance that is available to other modules by injection.
import { Module } from '@nestjs/common';
import { LoggerConfig, LoggerModule } from '@wiredcraft/nestjs-bunyan-logger';
import configuration from './src/configuration';

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [configuration],
    }),
    LoggerModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return configService.get<LoggerConfig>('logger', { infer: true });
      },
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

A sample configuration file is as below,

export default () => ({
  logger: {
      name: 'awesome-app',
      streamType: 'FILE' | 'STDOUT',
      path: './logs/app.log', // only available for `FILE` streamType
      excludeReqPath: '/health', // the path that you want to skip logging
  }
});
  1. Inject the logger instance to your service and use it as you want.
import { Injectable } from '@nestjs/common';
import { Logger, Bunyan  } from '@wiredcraf/nestjs-bunyan-logger';

@Injectable()
export class CatService {
  constructor(
    @Logger() private logger: Bunyan,
  ) {
  }
}

Development

Installation

$ yarn install

Publish

$ npm version major|minor|patch
$ npm publish

License

MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @wiredcraft/nestjs-bunyan-logger

Weekly Downloads

13

Version

2.1.0

License

MIT

Unpacked Size

182 kB

Total Files

27

Last publish

Collaborators

  • agreatfool
  • stefan1105
  • apexblade
  • miffyliye
  • dejandoder
  • linrz
  • koknikol
  • eronekogin
  • aleksandar5595
  • shuaibird
  • dmwc
  • kunlun8809
  • draganmijajilovic
  • wiredcraft-bot
  • xavierchow
  • kaleocheng
  • flyingant
  • superbogy
  • lalawow
  • juhas