Axios Logger Interceptor
Log request and response, redact all possible PII sources by default, but allow to add custom redact paths so more info can be logged.
yarn add @ovotech/axios-logger
;;;;api.interceptors.request.uselogger.request.onFullfilled;api.interceptors.response.uselogger.response.onFullfilled, logger.response.onRejected;// ...api.get'/my/path';;api.post'/update/path', body, ;
You have 3 interceptors.
logger.request.onFullfilledused to setup the initial execution time. If omitted request time would not be logged.
logger.response.onFullfilledlogs a successful response
logger.response.onRejectedlogs an error
Each one can be omitted if you don't want or need that feature.
The log function will receive 3 arguments - level, meta and axios request config. The first one indicates what type of log level to use - "info" for success and "error" for error. The second contains an object of data to log.
uri: '/my/path'method: 'get'params: id: '10'requestBody: id: '10'responseBody: user: 'Name'status: 200responseTime: 21
responseBody will be "redacted", since they can contain personally identifiable information. You can control that with the
redactHeader. Its a comma separated list of dot delimited field paths to be redacted. Can contain wildcard
* path to target all array items.
For example to redact some fields.
You can also set redact at the axios instance level for global redaction rules:
You can perform different things on error / success by inspecting the "level" argument, passed to the log function.
Running the tests
You can run the tests with:
Coding style (linting, etc) tests
Style is maintained with prettier and tslint
Deployment is preferment by lerna automatically on merge / push to master, but you'll need to bump the package version numbers yourself. Only updated packages with newer versions will be pushed to the npm registry.
Have a bug? File an issue with a simple example that reproduces this so we can take a look & confirm.
Want to make a change? Submit a PR, explain why it's useful, and make sure you've updated the docs (this file) and the tests (see test folder).
This project is licensed under Apache 2 - see the LICENSE file for details