Socket
Book a DemoInstallSign in
Socket

log-http

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log-http

Log HTTP requests

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

Keywords

log

FAQs

Package last updated on 12 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts