Koa middleware for logging http queries to mongoDB.
Mongolog
saves data this way:
{
ip: '<clients ip address>',
date: '<short date>',
urls: {
url: '<url to resource>',
count: '<count of requests>'
}
}
Mongolog
data could be read from command line by mongolog-cli.
npm i koa-mongolog --save
Mongolog
could be used as koa
middleware this way.
var mongolog = require('mongolog'),
koa = require('koa'),
mongo = require('mongodb').MongoClient,
url = 'mongodb://localhost:27017/myproject',
port = 1337,
app = koa();
mongo.connect(url, function(error, db) {
if (error) {
console.error(error.message);
} else {
app.use(mongolog({
db: db
}));
app.use(function*(next) {
console.log(this.request.url);
yield next;
});
app.listen(port);
console.log('http://localhost:%s', port);
}
});
- mongolog express middleware.
MIT