How to log all axios calls from one place in code

前端 未结 6 1150
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 12:17

I am using axios for a react application and I would like to log all axios calls that I\'m making anywhere in the app. I\'m already using a single global instance of axios via t

6条回答
  •  粉色の甜心
    2021-01-30 12:56

    Use axios-debug-log

    1. npm install --save axios-debug-log
    2. require('axios-debug-log') before any axios call
    3. Set the environment variable DEBUG=axios

    By default, you'll see logs like the following:

      axios POST /api/auth/login +0ms
      axios 200  (POST http://localhost:8080/api/auth/login) +125ms
      axios POST /api/foo +0ms
      axios 200  (POST http://localhost:8080/api/foo) +15ms
    

    Refer to the docs for configuration and customization options.

提交回复
热议问题