@drizzle-http/logging-interceptor
v3.1.0
Published
Logging Interceptor for Drizzle-HTTP
Downloads
22
Maintainers
Readme
Logging Interceptor ·
Drizzle-Http interceptor that logs HTTP requests and responses.
The default Logger implementation uses Pino.
Installation
Make sure we have the core module @Drizzle-Http/core installed.
npm i @drizzle-http/core
npm i @drizzle-http/logging-interceptor
Node
Basic
import { LoggingInterceptor } from '@drizzle-http/logging-interceptor'
import { DrizzleBuilder } from "@drizzle-http/core";
import { UndiciCallFactory } from "@drizzle-http/undici";
const interceptor = new LoggingInterceptor()
const api = DrizzleBuilder
.newBuilder()
.baseUrl(address)
.callFactory(new UndiciCallFactory())
.addInterceptor(interceptor)
.build()
.create(API)
Customize
import { LoggingInterceptor } from '@drizzle-http/logging-interceptor'
import { Level } from "@drizzle-http/logging-interceptor";
import { DrizzleBuilder } from "@drizzle-http/core";
import { UndiciCallFactory } from "@drizzle-http/undici";
const interceptor = new LoggingInterceptor({ level: Level.Body, logger: customLogger })
interceptor.redactHeader('x-super-secret-header')
interceptor.redactHeaders(['x-other-secret-header', 'x-one-more-secret-header'])
const api = DrizzleBuilder
.newBuilder()
.baseUrl(address)
.callFactory(new UndiciCallFactory())
.addInterceptor(interceptor)
.build()
.create(API)
Browser
Basic
import { BrowserLoggingInterceptor } from '@drizzle-http/logging-interceptor'
const api = DrizzleBuilder
.newBuilder()
.baseUrl(address)
.callFactory(new UndiciCallFactory())
.addInterceptor(new BrowserLoggingInterceptor())
.build()
.create(API)
It's not possible to change the logger implementation from BrowserLoggingInterceptor. It will use console.log.