medplum / medplum

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

Add more granular log levels for MedplumClient #5009

Open jeffrey-peterson-vanna opened 4 months ago

jeffrey-peterson-vanna commented 4 months 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 3 months 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
  },
})
AldrinSeanPereira commented 2 months ago

Can I get assigned to this issue? If yes, could you also guide me where I can find the MedplumClient code. Thanks