Open History to see the last commit
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.