axios-debug-log
Advanced tools
Comparing version 0.3.0 to 0.4.0
'use strict' | ||
var axios = require('axios') | ||
var debug = require('debug')('axios') | ||
var axiosDebug = require('debug')('axios') | ||
@@ -28,3 +28,4 @@ var options = { | ||
function addLogger (instance) { | ||
function addLogger (instance, debug) { | ||
if (debug === undefined) debug = axiosDebug | ||
instance.interceptors.request.use(function (config) { | ||
@@ -53,3 +54,3 @@ options.request(debug, config) | ||
module.exports = function (userOptions) { | ||
exports = module.exports = function (userOptions) { | ||
for (var key in options) { | ||
@@ -61,1 +62,3 @@ if (key in userOptions) { | ||
} | ||
exports.addLogger = addLogger |
{ | ||
"name": "axios-debug-log", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Axios interceptor of logging requests & responses by debug.", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"author": "George Chung <Gerhut@GMail.com>", | ||
"license": "MIT", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
@@ -29,16 +29,16 @@ "url": "https://github.com/Gerhut/axios-debug-log/issues" | ||
"dependencies": { | ||
"debug": "^2.6.0" | ||
"debug": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"axios": "^0.15.0", | ||
"axios": ">=0.13.0", | ||
"mocha": "^3.2.0", | ||
"nyc": "^10.1.2", | ||
"should": "^11.2.0", | ||
"should-sinon": "0.0.5", | ||
"sinon": "^1.17.7", | ||
"standard": "^8.6.0" | ||
"nyc": "^11.0.2", | ||
"should": "^13.0.0", | ||
"should-sinon": "0.0.6", | ||
"sinon": "^4.0.0", | ||
"standard": "^10.0.2" | ||
}, | ||
"peerDependencies": { | ||
"axios": "^0.15.0" | ||
"axios": ">=0.13.0" | ||
} | ||
} |
# axios-debug-log | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/Gerhut/axios-debug-log.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/Gerhut/axios-debug-log.svg?branch=master)](https://travis-ci.org/Gerhut/axios-debug-log) | ||
[![Coverage Status](https://coveralls.io/repos/github/Gerhut/axios-debug-log/badge.svg?branch=master)](https://coveralls.io/github/Gerhut/axios-debug-log?branch=master) | ||
[![dependencies Status](https://david-dm.org/Gerhut/kroxy/status.svg)](https://david-dm.org/Gerhut/axios-debug-log) | ||
[![devDependencies Status](https://david-dm.org/Gerhut/kroxy/dev-status.svg)](https://david-dm.org/Gerhut/axios-debug-log?type=dev) | ||
[![dependencies Status](https://david-dm.org/Gerhut/axios-debug-log/status.svg)](https://david-dm.org/Gerhut/axios-debug-log) | ||
[![devDependencies Status](https://david-dm.org/Gerhut/axios-debug-log/dev-status.svg)](https://david-dm.org/Gerhut/axios-debug-log?type=dev) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
@@ -50,4 +51,16 @@ | ||
## 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') | ||
``` | ||
## License | ||
MIT |
26
test.js
@@ -81,5 +81,27 @@ /* eslint-env mocha */ | ||
it('should add custom debug logger to axios instance', () => { | ||
const spy = sinon.spy() | ||
const instance = axios.create({}) | ||
require('.').addLogger(instance, spy) | ||
return instance({ | ||
url: 'http://example.com/', | ||
adapter: config => Promise.resolve({ | ||
status: 200, | ||
statusText: 'OK', | ||
config | ||
}) | ||
}).then(() => { | ||
spy.should.be.calledTwice() | ||
spy.firstCall.should.be.calledWithExactly( | ||
'GET http://example.com/' | ||
) | ||
spy.secondCall.should.be.calledWithExactly( | ||
'200 OK', '(GET http://example.com/)' | ||
) | ||
}) | ||
}) | ||
it('should be able to set format of response & response logging', () => { | ||
const requestLogger = sinon.spy((debug, config) => debug(config.method)) | ||
const responseLogger = sinon.spy((debug, response) => debug(response.statusText)) | ||
const requestLogger = sinon.spy((debug, config) => debug(config.method.toUpperCase())) | ||
const responseLogger = sinon.spy((debug, response) => debug(response.statusText.toUpperCase())) | ||
require('.')({ | ||
@@ -86,0 +108,0 @@ request: requestLogger, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
45977
0
328
66
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.9(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.15.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removedfollow-redirects@1.0.0(transitive)
- Removedms@2.0.0(transitive)
Updateddebug@^3.0.0