项目作者: pereslavtsev

项目描述 :
Easy way to log all Axios calls
高级语言: TypeScript
项目地址: git://github.com/pereslavtsev/axios-log.git
创建时间: 2020-04-19T08:54:11Z
项目社区:https://github.com/pereslavtsev/axios-log

开源协议:MIT License

下载


axios-log

npm
npm
npm

Easy way to log all Axios calls

Alt text

Install

You should install axios-log as a development dependency. Don’t use that in production mode.

Using npm:

  1. $ npm i axios
  2. $ npm i -D axios-log

Using yarn:

  1. $ yarn add axios
  2. $ yarn add -D axios-log

How to use

Logger can use as a axios‘s interceptor (Interceptors API).

Request Logging

Example:

  1. const axios = require('axios').default;
  2. const log = require('axios-log');
  3. const api = axios.create();
  4. api.interceptors.request.use(log.requestLogger);

Using modern ES6 syntax:

  1. import axios from 'axios';
  2. import { requestLogger } from 'axios-log';
  3. const api = axios.create();
  4. api.interceptors.request.use(requestLogger);

Also if you have some else interceptors, you should use requestLogger use it after those.

  1. import axios from 'axios';
  2. import { requestLogger } from 'axios-log';
  3. const api = axios.create();
  4. api.interceptors.request.use(someInterceptor1);
  5. api.interceptors.request.use(someInterceptor2);
  6. // ...you own interceptors
  7. api.interceptors.request.use(requestLogger);

Response Logging

Example:

  1. import axios from 'axios';
  2. import { responseLogger } from 'axios-log';
  3. const api = axios.create();
  4. api.interceptors.response.use(responseLogger);

Contributing

  1. Clone the project to your own machine;
  2. Checkout a new branch from master;
  3. Run a demo project:
    1. Install all package dependencies via npm: npm i
      or using yarn: yarn;
    2. Build the bundle in development mode: npm run dev or yarn dev;
    3. Link a current bundle location: npm link;
    4. Open a new terminal tab and change directory to demo: cd demo.

      There is a simple React-based app, but you can use any other repo for testing;
    5. Install demo dependencies in the same way as the library;
    6. Link axios-log package via npm link axios-log;
    7. Run the demo project via npm start or yarn start.

      Now any change from library source code will be applied in the demo project;
  4. Commit changes to your own branch;
  5. Push your work back up to your fork;
  6. Submit a Pull request so that we can review your changes.