@yoctol/axios-logger-mongo

0.4.1 • Public • Published

axios-logger-mongo

npm

Mongo logger interceptor for Axios.

Installation

Install using npm:

npm install @yoctol/axios-logger-mongo

API Reference

Param Type
mongoURL String URL of the mongodb.
collectionName String Name of the collection.
allInstances Boolean Support all of axios instances or not.
transformRequestBody Function Function to map request body.
transformResponseBody Function Function to map response body.

Usage

const { useMongoLogger } = require('@yoctol/axios-logger-mongo');

useMongoLogger(axios, {
  mongoURL: 'mongodb://localhost:27017/',
  collectionName: 'logs',
});

To support all of axios instances, set option allInstances to true:

useMongoLogger(axios, {
  mongoURL: 'mongodb://localhost:27017/',
  collectionName: 'logs',
  allInstances: true,
});

To transform your request, response before saving to database, use transformRequestBody or transformResponseBody:

useMongoLogger(axios, {
  mongoURL: 'mongodb://localhost:27017/',
  collectionName: 'logs',
  transformRequestBody: (body, { request, config } => { /* */ }),
  transformResponseBody: (body, { response, config } => { /* */ }),
});

Package Sidebar

Install

npm i @yoctol/axios-logger-mongo

Weekly Downloads

2

Version

0.4.1

License

MIT

Unpacked Size

15 kB

Total Files

7

Last publish

Collaborators

  • link515