import {Observable} from 'rxjs';
import {tap} from 'rxjs/operators';
export enum RxJsLoggingLevel {
TRACE,
DEBUG,
INFO,
WARN,
ERROR
}
let rxjsLoggingLevel = RxJsLoggingLevel.TRACE;
export function setRxJsLoggingLevel(level: RxJsLoggingLevel) {
rxjsLoggingLevel = level;
}
function a(level: number) {
return (message: string) => (source: Observable) => source
.pipe(
tap(val => {
if (level >= rxjsLoggingLevel) {
console.log(message + ': ', val);
}
})
);
}
export function t(message: string) {
return a(RxJsLoggingLevel.TRACE)(message)
}
export function d(message: string) {
return a(RxJsLoggingLevel.DEBUG)(message)
}
export function i(message: string) {
return a(RxJsLoggingLevel.INFO)(message)
}
export function w(message: string) {
return a(RxJsLoggingLevel.WARN)(message)
}
export function e(message: string) {
return a(RxJsLoggingLevel.ERROR)(message)
}
Then use anywhere like :
observable.pipe(
d(`next value is `)
)