axios-debug-log
v1.0.0
Published
Axios interceptor of logging requests & responses by debug.
Downloads
326,826
Readme
axios-debug-log
Axios interceptor of logging requests & responses by debug.
Install
$ npm install --save axios axios-debug-log
Node.js usage
- Install: add
require('axios-debug-log')
before any axios execution.- Enable: set
DEBUG=axios
environment variables before start your fantastic Node.js application.
Or
Add
require('axios-debug-log/enable')
before any axios execution to install and enable.
Or
Run DEBUG=axios node --require axios-debug-log [entrypoint.js]
Or
Run node --require axios-debug-log/enable [entrypoint.js]
Browser usage
- Install: add
require('axios-debug-log')
before any axios execution.- Enable: set
localStorage.debug = "axios"
before start your fantastic web application.
Or
Add
require('axios-debug-log/enable')
before any axios execution to install and enable.
Please read README of debug for usage details.
Configuration
// Log content type
require('axios-debug-log')({
request: function (debug, config) {
debug('Request with ' + config.headers['content-type'])
},
response: function (debug, response) {
debug(
'Response with ' + response.headers['content-type'],
'from ' + response.config.url
)
},
error: function (debug, error) {
// Read https://www.npmjs.com/package/axios#handling-errors for more info
debug('Boom', error)
}
})
Customization
Use require('axios-debug-log').addLogger(instance, debug)
to add custom debug
logger to custom instance.
var github = axios.create({ baseURL: 'https://api.github.com/' })
var githubLogger = require('debug')('github')
require('axios-debug-log').addLogger(github, githubLogger)
github('/user')
Trust by
And Yours...
License
MIT