medplum / medplum

Medplum is a healthcare platform that helps you quickly develop high-quality compliant applications.
https://medplum.com
Apache License 2.0
1.34k stars 377 forks source link

Add more granular log levels for MedplumClient #5009

Open jeffrey-peterson-vanna opened 1 month ago

jeffrey-peterson-vanna commented 1 month ago

When I instantiate the SDK with MedplumClient({ verbose: true }), I get chatty logs that include the bearer token. If I do verbose: false I get no logs. Additional intermediate log levels would be very useful, especially in contexts where logs are aggregated and persisted. A log level that simply output the following would be great:

> GET https://api.medplum.com/fhir/R4/Patient
< 200 OK
dillonstreator commented 1 month ago

@jeffrey-peterson-vanna this should be possible by overriding the fetch method on the MedplumClient to hook into outgoing requests:

const medplum = new MedplumClient({
  fetch: async (input: RequestInfo, init?: RequestInit): Promise<Response> => {
    const response = await fetch(input, init)
    console.log(`${init?.method ?? 'GET'} ${input}`, response.status)
    return response
  },
})