GithubHelp home page GithubHelp logo

isabella232 / node-middleware-log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tabcorp/node-middleware-log

0.0 0.0 0.0 120 KB

Ndjson logging middleware

License: MIT License

JavaScript 100.00%

node-middleware-log's Introduction

node-middleware-log stability

npm version build status test coverage downloads js-standard-style

Ndjson logging middleware.

Installation

$ npm install node-middleware-log

Usage

const logMiddleware = require('middleware-log')
const http = require('http')

const logOpts = { requestBody: true }
const log = httpLogger(logOpts, process.stdout)

http.createServer(function (req, res) {
  log(req, res, function (err, res) {
    // logic
  })
}).listen()

express + bole

const logMiddleware = require('middleware-log')
const boleStream = require('bole-stream')
const express = require('express')
const bole = require('bole')

bole.output({ stream: process.stdout })

const app = express()
app.use(logMiddleware(boleStream({ level: 'info' })))
app.listen()

restify + bunyan

const logMiddleware = require('middleware-log')
const bunyanStream = require('bunyan-stream')
const restify = require('restify')
const bunyan = require('bunyan')

const logger = bunyan.createLogger({ name: 'myApp' })

const server = restify.createServer()
server.use(logMiddleware(bunyanStream({ level: 'info' }, logger)))

API

log = logMiddleware(opts, outStream)

Create logging middleware. Options can contain the following values:

  • requestBody: log the requests body. Requires req.body to exist, which is often patched on by frameworks such as express or restify.

log(req, res, cb(err, res))

Log a request and response, calls a callback after it's finished initializing.

Limitations

In order to be compatible with popular frameworks such as express and restify, middleware-log has had to make tradeoffs. To get properties such as response size, Node's native properties are being patched on every request. Also, to log the request size this package also relies on a non-standard req.body value to be present. If you'd like to roll your own middleware-log with different tradeoffs take a look at size-stream and http-ndjson.

License

MIT

node-middleware-log's People

Contributors

yoshuawuyts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.