Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

setLogger.md

43 lines882 Bytes

1---
2id: setLogger
3title: setLogger
4---
5​
6## `setLogger`
7​
8`setLogger` is an optional function that allows you to replace the default `logger` used by React Query to log errors. By default, the `window.console` object is used. If no global `console` object is found in the environment, nothing will be logged.
9​
10Examples:
11​
12```js
13import { setLogger } from 'react-query'
14import { printLog, printWarn, printError } from 'custom-logger'
15​
16// Custom logger
17setLogger({
18 log: printLog,
19 warn: printWarn,
20 error: printError,
21})
22​
23// Sentry logger
24setLogger({
25 log: message => {
26 Sentry.captureMessage(message)
27 },
28 warn: message => {
29 Sentry.captureMessage(message)
30 },
31 error: error => {
32 Sentry.captureException(error)
33 },
34})
35​
36// Winston logger
37setLogger(winston.createLogger())
38```
39​
40**Options**
41​
42- `logger: Logger`
43 - Must implement the `log`, `warn`, and `error` methods.