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

4.1.0 • Public • Published

@qiwi/nestjs-enterprise-logger

Nestjs module for logging based on winston

Installation

Following packages should be installed before

yarn add @qiwi/nestjs-enterprise-logger

Configuration

Import

import { 
  LoggerModule,
  createMetaPipe,
  maskerLoggerPipeFactory,
 } from '@qiwi/nestjs-enterprise-logger'

@Module({
  imports: [
    ConfigModule,
    LoggerModule.register(createMetaPipe(), maskerLoggerPipeFactory()),
    // and so on
  ]
})

export class AppModule {}

Usage

  @Injectable()
  class MyService {
    constructor(@Inject('ILogger') private logger: ILogger) {}
    myError() {
      this.logger.error('foo')
    }
    myInfo() {
      this.logger.info('foo')
    }

  }

For createMetaPipe

import {
  logger as log,
} from '@qiwi/nestjs-enterprise-logger'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  const logger = app.get('ILogger')
  app
    .use(log({ logger }))
    .useLogger(logger)

 //...
 logger.info()

Customization

You can inject functions of type TLoggerPipe as your own pipes when create LoggerService or register LoggerModule. Your pipes will be inserted in the following order:

  • mdc pipe from @qiwi/logwrap;
  • app pipe (adds app name, app version and os info to log entry);
  • your own pipe;
  • ...
  • your own pipe;
  • logger pipe (prints log entry).

API

Class LoggerModule

Exports LoggerService with token ILogger

register (...pipes: TLoggerPipe[]): DynamicModule

Class LoggerService

constructor(pipeline: TLoggerPipe[], config: IConfig)

push(entry: ILogEntry): void

field type description
LogEntry.meta Record<string, any> Metadata
LogEntry.level ERROR | WARN | INFO | DEBUG | TRACE Log level
LogEntry.input any[] Data

trace(...data: any[]): void

debug(...data: any[]): void

info(...data: any[]): void

warn(...data: any[]): void

error(...data: any[]): void

Function createMetaPipe = () => (entry: ILogEntry): ILogEntry

Creates pipe for metadata injection, used with @qiwi-private/js-platform-mdc-nestjs

Function maskerLoggerPipeFactory = () => (entry: ILogEntry): ILogEntry

Creates pipe for pan masking

Function masker = (input: string | number): string

Masks pans

Docs

Readme

Keywords

Package Sidebar

Install

npm i @qiwi/nestjs-enterprise-logger

Weekly Downloads

1

Version

4.1.0

License

MIT

Unpacked Size

243 kB

Total Files

42

Last publish

Collaborators

  • antongolub
  • qiwibot