RestLog

auto manage web app log working with restful api
中文
Data struct
{
userId: '',
resource: '',
operation: '',
status: 1,
createdAt: '',
originRequest: {
url: '',
method: '',
ip: '',
userAgent: '',
body: {}
},
originResponse: {
statusCode: 200,
body: {}
}
}
Usage
import Koa from 'koa'
import RestLog from 'restlog'
const koa = new Koa()
const restLog = new RestLog({
dbSaver: {
dbClient: MongoDBInstance,
collectionName: 'demo'
},
getUserId: async (ctx)=> {
return 'test-user'
},
getResource async (ctx)=> {
return 'test-resource'
},
filter: (url)=> {
return true
},
localPath: 'path/to/save/logs/temporary',
uploadCondition: {
filesLimit: 2,
fileSizeLimit: 10,
fileExpireTime: 3 * 60,
intervalTime: 60,
}
})
app.use(restLog.getMiddleware())
app.listen()