@rnw-community/nestjs-rxjs-logger
TypeScript icon, indicating that this package has built-in type declarations

0.80.0 • Public • Published

NestJS RxJS logger

NestJS default logger wrapper for using with RxJS streams.

npm version npm downloads

Supported log levels

  • error - error$ RxJS operator
  • info - info$ RxJS operator
  • warn - warn$ RxJS operator
  • debug - debug$ RxJS operator
  • verbose - verbose$ RxJS operator

Configuration

Import NestJsRxJsLoggerModule into your module:

import { Logger, Module } from '@nestjs/common';
import { NestJsRxjsLoggerService } from '@rnw-community/nestjs-rxjs-logger';

@Module({
    imports: [NestJsRxJsLoggerModule],
    providers: [],
    exports: [],
})
export class MyModule {}

Inject NestJsRxjsLoggerService into your service:

import { Injectable } from '@nestjs/common';
import { NestJsRxjsLoggerService } from '@rnw-community/nestjs-rxjs-logger';
import { mapTo } from 'rxjs';

@Injectable()
export class MyService {
    constructor(private readonly logger: NestJsRxjsLoggerService) {}
}

Usage examples

Basic operators example

import { Injectable } from '@nestjs/common';
import { NestJsRxjsLoggerService } from '@rnw-community/nestjs-rxjs-logger';
import { mapTo } from 'rxjs';

@Injectable()
export class MyService {
    constructor(private readonly logger: NestJsRxjsLoggerService) {}

    loggerOperatorExample$(): Observable<true> {
        return of(true).pipe(this.logger.info$('My message', 'OtherContext'));
    }
}

Create stream example

import { Injectable } from '@nestjs/common';
import { NestJsRxjsLoggerService } from '@rnw-community/nestjs-rxjs-logger';
import { mapTo } from 'rxjs';

@Injectable()
export class MyService {
    constructor(private readonly logger: NestJsRxjsLoggerService) {}

    loggerCreateStreamExample$(): Observable<number> {
        return this.logger.create$('My message', MyService.name).pipe(mapTo(1));
    }
}

Set logger context

import { Injectable } from '@nestjs/common';
import { NestJsRxjsLoggerService } from '@rnw-community/nestjs-rxjs-logger';
import { mapTo } from 'rxjs';

@Injectable()
export class MyService {
    constructor(private readonly logger: NestJsRxjsLoggerService) {
        this.logger.setContext(MyService.name);
    }

    loggerOperatorExample$(): Observable<true> {
        return of(true).pipe(this.logger.info$('My message'));
    }

    loggerCreateStreamExample$(): Observable<number> {
        return this.logger.create$('My message').pipe(mapTo(1));
    }
}

License

This library is licensed under The MIT License.

Package Sidebar

Install

npm i @rnw-community/nestjs-rxjs-logger

Weekly Downloads

407

Version

0.80.0

License

MIT

Unpacked Size

49.9 kB

Total Files

35

Last publish

Collaborators

  • vitalyiegorov