Easy way to log all Axios calls
You should install axios-log
as a development dependency. Don't use that in production mode.
Using npm:
$ npm i axios
$ npm i -D axios-log
Using yarn:
$ yarn add axios
$ yarn add -D axios-log
Logger can use as a axios
's interceptor (Interceptors API).
Example:
const axios = require('axios').default;
const log = require('axios-log');
const api = axios.create();
api.interceptors.request.use(log.requestLogger);
Using modern ES6 syntax:
import axios from 'axios';
import { requestLogger } from 'axios-log';
const api = axios.create();
api.interceptors.request.use(requestLogger);
Also if you have some else interceptors, you should use requestLogger
use it after those.
import axios from 'axios';
import { requestLogger } from 'axios-log';
const api = axios.create();
api.interceptors.request.use(someInterceptor1);
api.interceptors.request.use(someInterceptor2);
// ...you own interceptors
api.interceptors.request.use(requestLogger);
Example:
import axios from 'axios';
import { responseLogger } from 'axios-log';
const api = axios.create();
api.interceptors.response.use(responseLogger);
- Clone the project to your own machine;
- Checkout a new branch from
master
; - Run a demo project:
- Install all package dependencies via npm:
npm i
or using yarn:yarn
; - Build the bundle in development mode:
npm run dev
oryarn dev
; - Link a current bundle location:
npm link
; - 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; - Install demo dependencies in the same way as the library;
- Link
axios-log
package vianpm link axios-log
; - Run the demo project via
npm start
oryarn start
.
Now any change from library source code will be applied in the demo project;
- Install all package dependencies via npm:
- Commit changes to your own branch;
- Push your work back up to your fork;
- Submit a Pull request so that we can review your changes.