Better Fetch
Utility

Logger

The logger plugin logs information on request, error or success and on retry.

npm i @better-fetch/logger

Usage

fetch.ts
import {  } from "@better-fetch/fetch";
import {  } from "@better-fetch/logger";
 
const  = ({
    : "http://localhost:3000",
    : [
        (),
    ],
});

Options

enabled

Enable or disable the logger.

fetch.ts
import { createFetch } from "@better-fetch/fetch";
import { logger } from "@better-fetch/logger";
 
const $fetch = createFetch({
    baseURL: "http://localhost:3000",
    plugins: [
        logger({
            enabled: process.env.NODE_ENV === "development",
        }),
    ],
});

console

By default the logger plugin uses the consola package to log the requests and responses. You can pass a custom console object to the logger plugin to use a different logger.

fetch.ts
import { createFetch } from "@better-fetch/fetch";
import { logger } from "@better-fetch/logger";
 
const $fetch = createFetch({
    baseURL: "http://localhost:3000",
    plugins: [
        logger({
            console: {
                log: (...args) => console.log(...args),
                error: (...args) => console.error(...args),
                warn: (...args) => console.warn(...args),
            },
        }),
    ],
});

verbose

Enable or disable verbose mode.

fetch.ts
import {  } from "@better-fetch/fetch";
import {  } from "@better-fetch/logger";
 
const  = ({
    : "http://localhost:3000",
    : [
        ({
            : true,
        }),
    ],
});

On this page