Skip to content

Instantly share code, notes, and snippets.

@jhades
Last active March 12, 2021 19:50
Show Gist options
  • Save jhades/15279d8bfae0a1a960f38452128445f3 to your computer and use it in GitHub Desktop.
Save jhades/15279d8bfae0a1a960f38452128445f3 to your computer and use it in GitHub Desktop.
onSelectUser(participantId:string) {
this.participantsService.findParticipantById(parseInt(participantId))
.pipe(
debug(LogginLevel.DEBUG, "Loading participant from backend")
)
.subscribe(
participant => {
...
},
console.error
);
}
findParticipantById(participantId: number): Observable<Participant> {
return this.http.get(`/api/participants/${participantId}`)
.pipe(
tap( res => console.log('HTTP response:', res)),
map(res => res.json().payload),
tap(console.log)
)
}
import {Observable} from 'rxjs';
import {tap} from 'rxjs/operators';
export enum RxJsLoggingLevel {
TRACE,
DEBUG,
INFO,
ERROR
}
let rxjsLoggingLevel = RxJsLoggingLevel.INFO;
export function setRxJsLoggingLevel(level: RxJsLoggingLevel) {
rxjsLoggingLevel = level;
}
export const debug = (level: number, message:string) =>
(source: Observable<any>) => source
.pipe(
tap(val => {
if (level >= rxjsLoggingLevel) {
console.log(message + ': ', val);
}
})
);
@esfomeado
Copy link

Property 'debug' does not exist on type 'Observable'.

Angular 10.

@Snider
Copy link

Snider commented Mar 12, 2021

debug(LogginLevel.DEBUG, "Loading participant from backend")

should be

debug(RxJsLoggingLevel.DEBUG, "Loading participant from backend")

This is great, ty, just what I need to help debug an SSR issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment