Skip to content

Instantly share code, notes, and snippets.

@sashaaro
Created February 14, 2021 19:02
Show Gist options
  • Save sashaaro/ad138ad6eafde27021b7a38731db9dbc to your computer and use it in GitHub Desktop.
Save sashaaro/ad138ad6eafde27021b7a38731db9dbc to your computer and use it in GitHub Desktop.
log rxjs operator
import { OperatorFunction } from 'rxjs';
import { tap } from 'rxjs/operators';
export function log<T>(prefix: string = null): OperatorFunction<T, T> {
return tap(
(data: T) => logIt(prefix, data),
err => logIt(prefix + '[ERROR]', err),
() => {
window.console.group(prefix + '[COMPLETE]')
window.console.groupEnd()
},
);
}
function logIt(prefix?: string, data?: any): void {
if (prefix) {
window.console.group(prefix);
window.console.log(data);
window.console.groupEnd();
} else {
window.console.log(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment