Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-pino-logger

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-pino-logger - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

22

logger.js
'use strict'
var pino = require('pino')
var eos = require('end-of-stream')
var maxInt = 2147483647

@@ -28,5 +27,8 @@

function onResFinished (err, res, startTime) {
var end = process.hrtime(startTime)
var log = res.log
function onResFinished (err) {
this.removeListener('finish', onResFinished)
this.removeListener('error', onResFinished)
var end = process.hrtime(this.startTime)
var log = this.log
var responseTime = Math.round(end[0] * 1e3 + end[1] / 1e6)

@@ -36,5 +38,5 @@

log.error({
res: res,
res: this,
err: err,
responseTime: responseTime
responseTime: this.responseTime
}, 'request errored')

@@ -45,3 +47,3 @@ return

log.info({
res: res,
res: this,
responseTime: responseTime

@@ -60,6 +62,6 @@ }, 'request completed')

res.log = child
res.startTime = startTime
eos(res, function (err) {
onResFinished(err, res, startTime)
})
res.on('finish', onResFinished)
res.on('error', onResFinished)

@@ -66,0 +68,0 @@ if (next) {

{
"name": "express-pino-logger",
"version": "0.2.2",
"version": "0.2.3",
"description": "An express middleware to log with pino",

@@ -29,3 +29,2 @@ "main": "logger.js",

"dependencies": {
"end-of-stream": "^1.1.0",
"pino": "^2.1.0"

@@ -32,0 +31,0 @@ },

@@ -1,14 +0,41 @@

# express-pino-logger
# express-pino-logger  [![Build Status](https://travis-ci.org/mcollina/express-pino-logger.svg)](https://travis-ci.org/mcollina/express-pino-logger)
An [express](http://npm.im/express) middleware to log with
[pino](https://github.com/mcollina/pino).
[pino](https://github.com/mcollina/pino). Incidentally, it also works
without express.
From our benchmarks, this is 4x faster than
[express-bunyan-logger](http://npm.im/express-bunyan-logger) and 25%
faster than [winston-express](http://npm.im/winston-express).
It is slightly slower (< 5%) than [morgan](http://npm.im/morgan),
which is a usecase-specific logger. With
[extreme](https://github.com/mcollina/pino#extreme) mode enable, it is
faster than morgan.
To our knowledge, `express-pino-logger` is the [fastest](#benchmarks) [express](http://npm.im/express) logger in town.
* [Installation](#install)
* [Usage](#usage)
* [Benchmarks](#benchmarks)
* [API](#api)
* [Team](#team)
* [Acknowledgements](#acknowledgements)
* [License](#license)
## Benchmarks
Benchmarks log each request/response pair while returning
`'hello world'`, using
[autocannon](https://github.com/mcollina/autocannon) with 100
connections and 10 pipelined requests.
* `express-bunyan-logger`: 1950 req/sec
* `express-winston`: 4739 req/sec
* `morgan`: 5812 req/sec
* `express-pino-logger`: 6108 req/sec
* `express-pino-logger` (extreme): 6594 req/sec
* `express-pino-logger` (without express and extreme): 11988 req/sec
All benchmarks where taken on a Macbook Pro 2014 (i7, 16GB of RAM).
Whilst we're comparing `express-pino-logger` against [morgan](http://npm.im/morgan), this isn't really a fair contest.
Morgan doesn't support logging arbitrary data, nor does it output JSON. Further Morgan [uses a form of `eval`](https://github.com/expressjs/morgan/blob/5da5ff1f5446e3f3ff29d29a2d6582712612bf89/index.js#L383) to achieve high speed logging. Whilst probably safe, using `eval` at all tends to cause concern, particular when it comes to server-side JavaScript.
The fact that `express-pino-logger` achieves higher throughput with JSON logging **and** arbitrary data, without using `eval`, serves to emphasise the high-speed capabilities of `express-pino-logger`.
With `express-pino-logger` you can have features, safety **and** speed.
## Install

@@ -81,2 +108,4 @@

[pino](http://npm.im/pino), look at them there.
`express-pino-logger` attaches some listeners to the request, so that
it will log when the request is completed.

@@ -83,0 +112,0 @@ ## License

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc