Skip to content
/ restlog Public

auto manage web app log working with restful api

License

Notifications You must be signed in to change notification settings

air-cc/restlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RestLog

Build status

auto manage web app log working with restful api

中文

Data struct

{
  userId: '',
  resource: '',
  operation: '',        // operation type. default use HTTP methods get / post / put / delete
  status: 1,            // operation result. 1 - succeed, -1 - fail, 0 - unknown
  createdAt: '',
  originRequest: {      // original request data
    url: '',
    method: '',
    ip: '',
    userAgent: '',
    body: {}
  },
  originResponse: {     // original response data
    statusCode: 200,
    body: {}
  }
}

Usage

import Koa from 'koa'
import RestLog from 'restlog'

const koa = new Koa()

// create restLog instance
const restLog = new RestLog({
  dbSaver: {                            // MongoDB config
    dbClient: MongoDBInstance,
    collectionName: 'demo'
  },
  getUserId: async (ctx)=> {           // get now user id
    return 'test-user'
  },
  getResource async (ctx)=> {          // get now resource (operation object) id
    return 'test-resource'
  },
  filter: (url)=> {                    // url filter, return false when this url do not need log
    return true
  },
  localPath: 'path/to/save/logs/temporary',   // local path for saving log
  uploadCondition: {                   // upload logs condition
    filesLimit: 2,                     //
    fileSizeLimit: 10,                 // KB
    fileExpireTime: 3 * 60,            // Second
    intervalTime: 60,                  // Second
  }
})

// add koa middleware
app.use(restLog.getMiddleware())


/**
 * pull log info
 * restLog.search({startAt, endAt, userId, resource, operation, page, pageSize})
 */

app.listen()

About

auto manage web app log working with restful api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published