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

pino-http

Package Overview
Dependencies
Maintainers
4
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-http - npm Package Compare versions

Comparing version 7.0.0 to 7.1.0

deprecations.js

4

benchmarks/http-ndjson-equivalent-server.js

@@ -13,4 +13,4 @@ 'use strict'

const opts = {
pid: pid,
hostname: hostname,
pid,
hostname,
level: 30,

@@ -17,0 +17,0 @@ res: {

@@ -47,3 +47,21 @@ // Project: https://github.com/pinojs/pino-http#readme

ignore?: ((req: IncomingMessage) => boolean);
/**
* @deprecated since version 7.1.0, use autologging.ignore instead
* @example
* const logger = pinoHttp({
* autoLogging: {
* ignore: req => req.url === '/ignorethis'
* }
* })
*/
ignorePaths?: Array<string | RegExp> | undefined;
/**
* @deprecated since version 7.1.0, use autologging.ignore instead
* @example
* const logger = pinoHttp({
* autoLogging: {
* ignore: req => req.originalUrl === '/ignorethis'
* }
* })
*/
getPath?: ((req: IncomingMessage) => string | undefined) | undefined;

@@ -78,7 +96,7 @@ }

}
interface ServerResponse {
err?: Error | undefined;
}
interface OutgoingMessage {

@@ -88,2 +106,1 @@ [startTime]: number;

}

@@ -9,2 +9,3 @@ 'use strict'

const reqObject = Symbol('reqObject')
const warning = require('./deprecations')

@@ -71,7 +72,13 @@ function pinoLogger (opts, stream) {

const autoLoggingIgnorePaths = (opts.autoLogging && opts.autoLogging.ignorePaths) ? opts.autoLogging.ignorePaths : []
if (opts.autoLogging !== undefined && opts.autoLogging.ignorePaths !== undefined) {
warning.emit('PINOHTTP_DEP001')
}
const autoLoggingGetPath = opts.autoLogging && opts.autoLogging.getPath ? opts.autoLogging.getPath : null
if (opts.autoLogging !== undefined && opts.autoLogging.getPath !== undefined) {
warning.emit('PINOHTTP_DEP002')
}
delete opts.autoLogging
const receivedMessage = opts.customReceivedMessage && typeof opts.customReceivedMessage === 'function' ? opts.customReceivedMessage : undefined
const successMessage = opts.customSuccessMessage || function () { return 'request completed' }
const successMessage = opts.customSuccessMessage || function (req, res) { return res.writableEnded ? 'request completed' : 'request aborted' }
const errorMessage = opts.customErrorMessage || function () { return 'request errored' }

@@ -89,2 +96,3 @@ delete opts.customSuccessfulMessage

function onResFinished (err) {
this.removeListener('close', onResFinished)
this.removeListener('error', onResFinished)

@@ -177,2 +185,3 @@ this.removeListener('finish', onResFinished)

res.on('close', onResFinished)
res.on('finish', onResFinished)

@@ -179,0 +188,0 @@ }

{
"name": "pino-http",
"version": "7.0.0",
"version": "7.1.0",
"description": "High-speed HTTP logger for Node.js",

@@ -11,3 +11,4 @@ "main": "logger.js",

"pino": "^7.5.0",
"pino-std-serializers": "^5.0.0"
"pino-std-serializers": "^5.0.0",
"process-warning": "^2.0.0"
},

@@ -14,0 +15,0 @@ "devDependencies": {

@@ -102,4 +102,4 @@ # pino-http&nbsp;&nbsp;[![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-http/CI)](https://github.com/pinojs/pino-http/actions)

* `autoLogging.ignore`: set to a `function (req) => { /* returns boolean */ }`. Useful for defining logic based on req properties (such as a user-agent header) to ignore successful requests.
* `autoLogging.ignorePaths`: array that holds one or many paths that should not autolog on completion. Paths will be matched exactly to the url path `req.url` (using Node class `URL.pathname`). This is useful for ignoring e.g. health check paths that get called every X seconds, and would fill out the logs unnecessarily. If the path matches and succeeds (http 200), it will not log any text. If it fails, it will log the error (as with any other path).
* `autoLogging.getPath`: set to a `function (req) => { /* returns path string */ }`. This function will be invoked to return the current path as a string. This is useful for checking `autoLogging.ignorePaths` against a path other than the default `req.url`. e.g. An express server where `req.originalUrl` is preferred.
* `autoLogging.ignorePaths(deprecated in favor of autoLogging.ignore)`: array that holds one or many paths that should not autolog on completion. Paths will be matched exactly to the url path `req.url` (using Node class `URL.pathname`). This is useful for ignoring e.g. health check paths that get called every X seconds, and would fill out the logs unnecessarily. If the path matches and succeeds (http 200), it will not log any text. If it fails, it will log the error (as with any other path).
* `autoLogging.getPath(deprecated in favor of autoLogging.ignore)`: set to a `function (req) => { /* returns path string */ }`. This function will be invoked to return the current path as a string. This is useful for checking `autoLogging.ignorePaths` against a path other than the default `req.url`. e.g. An express server where `req.originalUrl` is preferred.
* `stream`: same as the second parameter

@@ -106,0 +106,0 @@ * `customReceivedMessage`: set to a `function (req, res) => { /* returns message string */ }` This function will be invoked at each request received, setting "msg" property to returned string. If not set, nothing value will be used.

@@ -5,2 +5,4 @@ 'use strict'

const http = require('http')
const net = require('net')
const stream = require('stream')
const pinoHttp = require('../')

@@ -16,2 +18,3 @@ const pino = require('pino')

const DEFAULT_REQUEST_COMPLETED_MSG = 'request completed'
const DEFAULT_REQUEST_ABORTED_MSG = 'request aborted'
const DEFAULT_REQUEST_ERROR_MSG = 'request errored'

@@ -247,3 +250,3 @@

const logger = pinoHttp({ genReqId: genReqId }, dest)
const logger = pinoHttp({ genReqId }, dest)
setup(t, logger, function (err, server) {

@@ -360,2 +363,44 @@ t.error(err)

test('log requests aborted during payload', function (t) {
const dest = split(JSON.parse)
const logger = pinoHttp(dest)
function handle (req, res) {
logger(req, res)
const read = new stream.Readable({
read () {
if (this.called) {
return
}
this.called = true
this.push('delayed')
}
})
read.pipe(res)
}
function listen (err, server) {
t.error(err)
const client = net.connect(server.address().port, server.address().address, () => {
client.write('GET /delayed HTTP/1.1\r\n\r\n')
})
client.on('data', (data) => {
client.destroy()
})
}
setup(t, logger, listen, handle)
dest.on('data', function (line) {
t.ok(line.responseTime >= 0, 'responseTime is defined')
t.equal(line.msg, DEFAULT_REQUEST_ABORTED_MSG, 'message is set')
t.end()
})
})
test('no auto logging with autoLogging set to false', function (t) {

@@ -375,2 +420,36 @@ const dest = split(JSON.parse)

test('should warn upon use of autLogging.ignorePaths', test => {
test.plan(1)
process.once('warning', warning => {
test.equal(warning.code, 'PINOHTTP_DEP001')
test.end()
})
pinoHttp({
autoLogging: {
ignorePaths: ['/ignorethis']
}
})
})
test('should warn upon use of autLogging.getPath', test => {
test.plan(1)
process.once('warning', warning => {
test.equal(warning.code, 'PINOHTTP_DEP002')
test.end()
})
pinoHttp({
autoLogging: {
getPath: req => req.url
}
})
})
/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths is removed from code base
*/
test('no auto logging with autoLogging set to true and path ignored', function (t) {

@@ -394,2 +473,6 @@ const dest = split(JSON.parse)

/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths is removed from code base
*/
test('auto logging with autoLogging set to true and path not ignored', function (t) {

@@ -414,2 +497,6 @@ const dest = split(JSON.parse)

/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths & autoLogging.getPath are removed from code base
*/
test('no auto logging with autoLogging set to true and getPath result is ignored', function (t) {

@@ -436,2 +523,6 @@ const dest = split(JSON.parse)

/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths & autoLogging.getPath are removed from code base
*/
test('auto logging with autoLogging set to true and getPath result is not ignored', function (t) {

@@ -459,2 +550,6 @@ const dest = split(JSON.parse)

/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths & autoLogging.getPath are removed from code base
*/
test('no auto logging with autoLogging set to use regular expressions. result is ignored', function (t) {

@@ -484,2 +579,43 @@ const dest = split(JSON.parse)

/**
* @deprecated since version 7.1.0
* TODO: remove test when autoLogging.ignorePaths & autoLogging.getPath are removed from code base
*/
test('autoLogging set to true and path ignored', test => {
const dest = split(JSON.parse)
const logger = pinoHttp({
autoLogging: {
ignore: req => req.url === '/ignorethis'
}
}, dest)
setup(test, logger, (err, server) => {
test.error(err)
doGet(server, '/ignorethis', () => {
const line = dest.read()
test.equal(line, null)
test.end()
})
})
})
test('autoLogging set to true and path not ignored', test => {
const dest = split(JSON.parse)
const logger = pinoHttp({
autoLogging: {
ignore: req => req.url === '/ignorethis'
}
}, dest)
setup(test, logger, function (err, server) {
test.error(err)
doGet(server, '/shouldlogthis')
})
dest.on('data', function (line) {
test.pass('path should log')
test.end()
})
})
test('no auto logging with autoLogging set to true and ignoring a specific user-agent', function (t) {

@@ -546,3 +682,3 @@ const dest = split(JSON.parse)

logger: pino(dest),
genReqId: genReqId
genReqId
})

@@ -549,0 +685,0 @@

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