You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> All log messages are intended for debugging only. The format and content of log messages
194
+
> may change between releases.
195
+
196
+
#### Log levels
197
+
198
+
The log level can be configured in two ways:
199
+
200
+
1. Via the `GITPOD_LOG` environment variable
201
+
2. Using the `logLevel` client option (overrides the environment variable if set)
202
+
203
+
```ts
204
+
importGitpodfrom'@gitpod/sdk';
205
+
206
+
const client =newGitpod({
207
+
logLevel: 'debug', // Show all log messages
208
+
});
209
+
```
210
+
211
+
Available log levels, from most to least verbose:
212
+
213
+
-`'debug'` - Show debug messages, info, warnings, and errors
214
+
-`'info'` - Show info messages, warnings, and errors
215
+
-`'warn'` - Show warnings and errors (default)
216
+
-`'error'` - Show only errors
217
+
-`'off'` - Disable all logging
218
+
219
+
At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.
220
+
Some authentication-related headers are redacted, but sensitive data in request and response bodies
221
+
may still be visible.
222
+
223
+
#### Custom logger
224
+
225
+
By default, this library logs to `globalThis.console`. You can also provide a custom logger.
226
+
Most logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.
227
+
228
+
When providing a custom logger, the `logLevel` option still controls which messages are emitted, messages
229
+
below the configured level will not be sent to your logger.
230
+
231
+
```ts
232
+
importGitpodfrom'@gitpod/sdk';
233
+
importpinofrom'pino';
234
+
235
+
const logger =pino();
236
+
237
+
const client =newGitpod({
238
+
logger: logger.child({ name: 'Gitpod' }),
239
+
logLevel: 'debug', // Send all messages to pino, allowing it to filter
240
+
});
241
+
```
242
+
190
243
### Making custom/undocumented requests
191
244
192
245
This library is typed for convenient access to the documented API. If you need to access undocumented
@@ -246,33 +299,12 @@ globalThis.fetch = fetch;
246
299
Or pass it to the client:
247
300
248
301
```ts
302
+
importGitpodfrom'@gitpod/sdk';
249
303
importfetchfrom'my-fetch';
250
304
251
305
const client =newGitpod({ fetch });
252
306
```
253
307
254
-
### Logging and middleware
255
-
256
-
You may also provide a custom `fetch` function when instantiating the client,
257
-
which can be used to inspect or alter the `Request` or `Response` before/after each request:
console.log('About to make a request', url, init);
266
-
const response =awaitfetch(url, init);
267
-
console.log('Got response', response);
268
-
returnresponse;
269
-
},
270
-
});
271
-
```
272
-
273
-
Note that if given a `GITPOD_LOG=debug` environment variable, this library will log all requests and responses automatically.
274
-
This is intended for debugging purposes only and may change in the future without notice.
275
-
276
308
### Fetch options
277
309
278
310
If you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)
0 commit comments