@xocomil/log-observable
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

log-observable

A simple observable logger based on article by Netanel Basal. It includes colors and seeds for different instances of the logger.

[!TIP] log-observable is a library to help debug observables during development. You should avoid using it in production.

Installation

npm

npm install @xocomil/log-observable --save-dev

pnpm

pnpm install @xocomil/log-observable -D

yarn

yarn add @xocomil/log-observable -D

Usage

Basic Usage

Basic Usage

The simplest case is just logging what your observable emits. You can add logObservable('some tag') anywhere in your observable pipe to see what is being emitted at that point.

import { logObservable } from '@xocomil/log-observable';

from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).pipe(logObservable('Simple Case')).subscribe();

Multiple Loggers in Same Pipe

Multiple Loggers Output

Each logger is given a unique ID and one of 8 colors to help differentiate between them. You can add multiple loggers to the same pipe to see what is happening at different points.

import { logObservable } from '@xocomil/log-observable';

from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  .pipe(
    logObservable('Simple Case'),
    map((value) => value ** 3),
    logObservable('Map Case'),
  )
  .subscribe();

Handling Errors

Error Handling

The logger handles errors and logs them in red. This can help you see where an error is occurring in your observable pipes.

import { logObservable } from '@xocomil/log-observable';

from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
  .pipe(
    logObservable('Simple Case'),
    map((value) => value ** 3),
    logObservable('Map Case'),
    tap((value) => {
      if (value >= 300) {
        throw new Error('Value is too high');
      }
    }),
    logObservable('Simple Error Case'),
  )
  .subscribe();

Package Sidebar

Install

npm i @xocomil/log-observable

Weekly Downloads

0

Version

0.4.0

License

none

Unpacked Size

19.9 kB

Total Files

11

Last publish

Collaborators

  • xocomil