import { HttpInterceptor , HttpHandler , HttpRequest , HttpEvent , HttpResponse } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import 'rxjs/add/operator/do' ; export class LogInterceptor implements HttpInterceptor { constructor ( ) { } intercept ( req , next ) { const started = Date . now ( ) ; return next . handle ( req ) . do ( event => { if ( event instanceof HttpResponse ) { const elapsed = Date . now ( ) - started ; console . log ( `Request for ${ req . urlWithParams } took ${ elapsed } ms.` ) ; } } ) ; } }