Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Gerhut/axios-debug-log
Axios interceptor of logging request & response with debug library.
https://github.com/Gerhut/axios-debug-log
axios debug logging
Last synced: 4 months ago
JSON representation
Axios interceptor of logging request & response with debug library.
- Host: GitHub
- URL: https://github.com/Gerhut/axios-debug-log
- Owner: Gerhut
- License: bsd-3-clause
- Created: 2017-02-02T02:42:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-01T04:22:44.000Z (5 months ago)
- Last Synced: 2024-10-02T12:46:02.908Z (5 months ago)
- Topics: axios, debug, logging
- Language: JavaScript
- Homepage: https://npm.im/axios-debug-log
- Size: 92.8 KB
- Stars: 133
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# axios-debug-log
[](https://github.com/Gerhut/axios-debug-log/actions/workflows/ci.yaml)
[](https://coveralls.io/github/Gerhut/axios-debug-log?branch=master)
[](http://standardjs.com/)[Axios](https://www.npmjs.com/package/axios) interceptor of logging requests & responses by [debug](https://www.npmjs.com/package/debug).

## Install
$ npm install --save axios axios-debug-log
## Node.js usage
> 1. Install: add `require('axios-debug-log')` before any axios execution.
> 2. 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\]
OR
> 1. Install: add when using ES modules (type: module) before any axios execution.
> ```js
> import { createRequire } from 'module';
> const require = createRequire(import.meta.url);
> require('axios-debug-log');
> const axios = require('axios');
> ```
> 2. Enable: set `DEBUG=axios` environment variables before start your fantastic Node.js application.## Browser usage
> 1. Install: add `require('axios-debug-log')` before any axios execution.
> 2. 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](https://github.com/visionmedia/debug#readme) for usage details.
## Configuration
```javascript
// 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.```javascript
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
[](https://github.com/octokit)
[](https://github.com/slackapi)
[](https://github.com/PublicI)
[](https://github.com/AppImage)
[](https://github.com/pytorch)*And Yours...*
## License
MIT