1.0.0 • Published 7 years ago

log-http v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

log-http stability

npm version build status downloads js-standard-style

Log HTTP requests. Works well with pino and pino-colada.

Usage

var logHttp = require('log-http')
var http = require('http')
var pino = require('pino')

var log = pino('http')

var server = http.createServer(function (req, res) {
  res.end('hello filthy planet')
})

var stats = logHttp(server)
stats.on('data', function (level, data) {
  log[level](data)
})

server.listen(8080)

Output

{"pid":42140,"hostname":"anons-MacBook.local","level":30,"time":1492003344167,"url":"/","method":"GET","message":"request","contentLength":89,"v":1}
{"pid":42140,"hostname":"anons-MacBook.local","level":30,"time":1492003344170,"url":"/","method":"GET","statusCode":200,"message":"response","elapsed":4,"contentLength":119,"v":1}
{"pid":42140,"hostname":"anons-MacBook.local","level":30,"time":1492003352734,"url":"/","method":"GET","message":"request","contentLength":89,"v":1}
{"pid":42140,"hostname":"anons-MacBook.local","level":30,"time":1492003352734,"url":"/","method":"GET","statusCode":200,"message":"response","elapsed":1,"contentLength":119,"v":1}

API

stats = logHttp(server)

Create a new stats emitter from a server instance.

stats.on('data', function(level, data))

Listen to a new incoming or outgoing request. Logs out the expected log level and corresponding data. Should be passed to a logger.

License

MIT