Infinity-EV / axios-logger-mongo

Mongo logger interceptor for Axios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 }) => {
    /* */
  },
});

About

Mongo logger interceptor for Axios


Languages

Language:JavaScript 100.0%