Skip to content

fortino645/koa-log-requests

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

koa-log-requests

Customizable Koa middleware for logging incoming requests. Outputs method, path, response status, time spent and request body.

Installation

$ npm install koa-log-requests --save

Usage

var koa = require('koa');
var requests = require('koa-log-requests');

var app = koa();

app.use(requests());
app.use(function * (next) {
	this.body = 'Hello World';
	
	yield next;
});

app.listen(3000);

Sample:

->  2016-05-26T18:19:29.551Z method=POST path=/test/rvs/inapp status=200 time=24ms body={"username":"fortino@ooyala.com","appstore":"roku","sku":"aaaaaaaaaa","receipt":"5AB3663A-AA82-4007-A079-A5DA011E6707"}
<-  2016-05-26T18:19:29.575Z method=POST path=/test/rvs/inapp status=200 time=24ms body={"error":{"message":"Invalid signature","code":401,"type":"Invalid_Signature_"},"success":false}

Options

There are few options, that you can customize:

var requests = require('koa-log-requests');

requests.indent = 2; // insert N spaces at the beginning
requests.format = ':date :method :path status=:status time=:time body=:body data=:custom'; // format of output
requests.filter = ['password', 'password_confirmation']; // filter out these keys from request body
requests.customData = function(){ return 'something'};  //print any information that you want

License

koa-log-requests is released under the MIT license.

About

Customizable Koa middleware for logging requests in console

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%