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
156
+
> may change between releases.
157
+
158
+
#### Log levels
159
+
160
+
The log level can be configured in two ways:
161
+
162
+
1. Via the `LIGHTSWITCH_LOG` environment variable
163
+
2. Using the `logLevel` client option (overrides the environment variable if set)
164
+
165
+
```ts
166
+
importLightswitchfrom'lightswitch-api';
167
+
168
+
const client =newLightswitch({
169
+
logLevel: 'debug', // Show all log messages
170
+
});
171
+
```
172
+
173
+
Available log levels, from most to least verbose:
174
+
175
+
-`'debug'` - Show debug messages, info, warnings, and errors
176
+
-`'info'` - Show info messages, warnings, and errors
177
+
-`'warn'` - Show warnings and errors (default)
178
+
-`'error'` - Show only errors
179
+
-`'off'` - Disable all logging
180
+
181
+
At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.
182
+
Some authentication-related headers are redacted, but sensitive data in request and response bodies
183
+
may still be visible.
184
+
185
+
#### Custom logger
186
+
187
+
By default, this library logs to `globalThis.console`. You can also provide a custom logger.
188
+
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.
189
+
190
+
When providing a custom logger, the `logLevel` option still controls which messages are emitted, messages
191
+
below the configured level will not be sent to your logger.
192
+
193
+
```ts
194
+
importLightswitchfrom'lightswitch-api';
195
+
importpinofrom'pino';
196
+
197
+
const logger =pino();
198
+
199
+
const client =newLightswitch({
200
+
logger: logger.child({ name: 'Lightswitch' }),
201
+
logLevel: 'debug', // Send all messages to pino, allowing it to filter
202
+
});
203
+
```
204
+
152
205
### Making custom/undocumented requests
153
206
154
207
This library is typed for convenient access to the documented API. If you need to access undocumented
@@ -208,33 +261,12 @@ globalThis.fetch = fetch;
208
261
Or pass it to the client:
209
262
210
263
```ts
264
+
importLightswitchfrom'lightswitch-api';
211
265
importfetchfrom'my-fetch';
212
266
213
267
const client =newLightswitch({ fetch });
214
268
```
215
269
216
-
### Logging and middleware
217
-
218
-
You may also provide a custom `fetch` function when instantiating the client,
219
-
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);
228
-
const response =awaitfetch(url, init);
229
-
console.log('Got response', response);
230
-
returnresponse;
231
-
},
232
-
});
233
-
```
234
-
235
-
Note that if given a `LIGHTSWITCH_LOG=debug` environment variable, this library will log all requests and responses automatically.
236
-
This is intended for debugging purposes only and may change in the future without notice.
237
-
238
270
### Fetch options
239
271
240
272
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