Skip to content

FreeWall/axios-console-logger

Repository files navigation

Axios Console Logger

npm version publish status

A console logger for Axios HTTP client.

Installation

npm install @freewall/axios-console-logger

Usage

import { AxiosConsoleLogger } from '@freewall/axios-console-logger';

const logger = new AxiosConsoleLogger();

axios.interceptors.request.use((request) => logger.request(request));

axios.interceptors.response.use(
  (response) => logger.response(response),
  (error) => logger.error(error),
);

Options

// default values:
new AxiosConsoleLogger({
  colors: {
    get: {
      request: '#54b7d3',
      response: '#408ba1',
    },
    post: {
      request: '#96c750',
      response: '#6f943b',
    },
  },
  multiline: false,
  responseSize: true,
  responseTime: true,
  requestKeys: ['params', 'data'],
  responseKeys: ['data'],
});