2.1.0 • Published 4 months ago

@wiredcraft/nestjs-bunyan-logger v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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.

2.1.0

4 months ago

2.0.1

5 months ago

2.0.0

1 year ago

1.2.0

2 years ago

1.5.0

1 year ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago