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 6.6.0 to 7.0.0

8

index.d.ts

@@ -31,9 +31,9 @@ // Project: https://github.com/pinojs/pino-http#readme

autoLogging?: boolean | AutoLoggingOptions | undefined;
customLogLevel?: ((res: ServerResponse, error: Error) => pino.LevelWithSilent) | undefined;
customLogLevel?: ((req: IncomingMessage, res: ServerResponse, error: Error) => pino.LevelWithSilent) | undefined;
customReceivedMessage?: ((req: IncomingMessage, res: ServerResponse) => string) | undefined;
customSuccessMessage?: ((res: ServerResponse) => string) | undefined;
customErrorMessage?: ((error: Error, res: ServerResponse) => string) | undefined;
customSuccessMessage?: ((req: IncomingMessage, res: ServerResponse) => string) | undefined;
customErrorMessage?: ((req: IncomingMessage, res: ServerResponse, error: Error) => string) | undefined;
customAttributeKeys?: CustomAttributeKeys | undefined;
wrapSerializers?: boolean | undefined;
reqCustomProps?: ((req: IncomingMessage, res: ServerResponse) => object) | undefined;
customProps?: ((req: IncomingMessage, res: ServerResponse) => object) | undefined;
quietReqLogger?: boolean | undefined;

@@ -40,0 +40,0 @@ }

@@ -27,4 +27,4 @@

pinoHttp({ autoLogging: { ignorePaths: ['/health'], getPath: (req: IncomingMessage) => req.url } });
pinoHttp({ customSuccessMessage: (req: ServerResponse) => 'Success' });
pinoHttp({ customErrorMessage: (error: Error, res: ServerResponse) => `Error - ${error}` });
pinoHttp({ customSuccessMessage: (req: IncomingMessage, res: ServerResponse) => 'Success' });
pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error) => `Error - ${error}` });
pinoHttp({ customAttributeKeys: { req: 'req' } });

@@ -35,4 +35,4 @@ pinoHttp({ customAttributeKeys: { res: 'res' } });

pinoHttp({ customAttributeKeys: { req: 'req', res: 'res', err: 'err', responseTime: 'responseTime' } });
pinoHttp({ customLogLevel: (res: ServerResponse, error: Error) => 'info' });
pinoHttp({ reqCustomProps: (req: IncomingMessage, res: ServerResponse) => ({ key1: 'value1', 'x-key-2': 'value2' }) });
pinoHttp({ customLogLevel: (req: IncomingMessage, res: ServerResponse, error: Error) => 'info' });
pinoHttp({ customProps: (req: IncomingMessage, res: ServerResponse) => ({ key1: 'value1', 'x-key-2': 'value2' }) });
pinoHttp({ wrapSerializers: false });

@@ -115,3 +115,3 @@ pinoHttp(new Writable());

autoLogging: canBeUndefined(autoLoggingOptions),
customLogLevel: canBeUndefined((res: ServerResponse, error: Error) => rtnLevel()),
customLogLevel: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error) => rtnLevel()),
customReceivedMessage: canBeUndefined((req, res) => {

@@ -121,7 +121,7 @@ res.setHeader('x-custom-header-123', 'custom-header-value');

}),
customSuccessMessage: canBeUndefined((res: ServerResponse) => 'successMessage'),
customErrorMessage: canBeUndefined((error: Error, res: ServerResponse) => 'errorMessage'),
customSuccessMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse) => 'successMessage'),
customErrorMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error) => 'errorMessage'),
customAttributeKeys: canBeUndefined(customAttributeKeys),
wrapSerializers: canBeUndefined(rtnBool()),
reqCustomProps: canBeUndefined((req: IncomingMessage, res: ServerResponse) => ({} as object)),
customProps: canBeUndefined((req: IncomingMessage, res: ServerResponse) => ({} as object)),
quietReqLogger: canBeUndefined(rtnBool()),

@@ -128,0 +128,0 @@ }

@@ -26,3 +26,3 @@ 'use strict'

const customProps = opts.customProps || opts.reqCustomProps || undefined
const customProps = opts.customProps || undefined

@@ -57,3 +57,3 @@ opts.wrapSerializers = 'wrapSerializers' in opts ? opts.wrapSerializers : true

function getLogLevelFromCustomLogLevel (customLogLevel, useLevel, res, err, req) {
return customLogLevel ? getValidLogLevel(customLogLevel(res, err, req), useLevel) : useLevel
return customLogLevel ? getValidLogLevel(customLogLevel(req, res, err), useLevel) : useLevel
}

@@ -115,3 +115,3 @@

[responseTimeKey]: responseTime
}, errorMessage(error, this))
}, errorMessage(req, this, error))
return

@@ -123,3 +123,3 @@ }

[responseTimeKey]: responseTime
}, successMessage(this))
}, successMessage(req, this))
}

@@ -126,0 +126,0 @@

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

@@ -22,6 +22,6 @@ "main": "logger.js",

"split2": "^4.0.0",
"standard": "^16.0.3",
"tap": "^15.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"ts-node": "^10.3.0",
"tsd": "^0.19.0",
"tsd": "^0.20.0",
"typescript": "^4.4.4"

@@ -28,0 +28,0 @@ },

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

* `useLevel`: the logger level `pino-http` is using to log out the response. default: `info`
* `customLogLevel`: set to a `function (res, err, req) => { /* returns level name string */ }`. This function will be invoked to determine the level at which the log should be issued (`silent` will prevent logging). This option is mutually exclusive with the `useLevel` option. The first argument is the HTTP response. The second argument is an error object if an error has occurred in the request.
* `customLogLevel`: set to a `function (req, res, err) => { /* returns level name string */ }`. This function will be invoked to determine the level at which the log should be issued (`silent` will prevent logging). This option is mutually exclusive with the `useLevel` option. The first two arguments are the HTTP request and response. The third argument is an error object if an error has occurred in the request.
* `autoLogging`: set to `false`, to disable the automatic "request completed" and "request errored" logging. Defaults to `true`. If set to an object, you can provide more options.

@@ -107,7 +107,7 @@ * `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.

* `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.
* `customSuccessMessage`: set to a `function (res) => { /* returns message string */ }` This function will be invoked at each successful response, setting "msg" property to returned string. If not set, default value will be used.
* `customErrorMessage`: set to a `function (err, res) => { /* returns message string */ }` This function will be invoked at each failed response, setting "msg" property to returned string. If not set, default value will be used.
* `customSuccessMessage`: set to a `function (req, res) => { /* returns message string */ }` This function will be invoked at each successful response, setting "msg" property to returned string. If not set, default value will be used.
* `customErrorMessage`: set to a `function (req, res, err) => { /* returns message string */ }` This function will be invoked at each failed response, setting "msg" property to returned string. If not set, default value will be used.
* `customAttributeKeys`: allows the log object attributes added by `pino-http` to be given custom keys. Accepts an object of format `{ [original]: [override] }`. Attributes available for override are `req`, `res`, `err`, `responseTime` and, when using quietReqLogger, `reqId`.
* `wrapSerializers`: when `false`, custom serializers will be passed the raw value directly. Defaults to `true`.
* `customProps`: set to a `function (req,res) => { /* returns on object */ }` or `{ /* returns on object */ }` This function will be invoked for each request with `req` and `res` where we could pass additional properties that needs to be logged outside the `req`.
* `customProps`: set to a `function (req, res) => { /* returns on object */ }` or `{ /* returns on object */ }` This function will be invoked for each request with `req` and `res` where we could pass additional properties that need to be logged outside the `req`.
* `quietReqLogger`: when `true`, the child logger available on `req.log` will no longer contain the full bindings and will now only have the request id bound at `reqId` (note: the autoLogging messages and the logger available on `res.log` will remain the same except they will also have the additional `reqId` property). default: `false`

@@ -148,3 +148,3 @@

// Define a custom logger level
customLogLevel: function (res, err) {
customLogLevel: function (req, res, err) {
if (res.statusCode >= 400 && res.statusCode < 500) {

@@ -161,11 +161,11 @@ return 'warn'

// Define a custom success message
customSuccessMessage: function (res) {
customSuccessMessage: function (req, res) {
if (res.statusCode === 404) {
return 'resource not found'
}
return 'request completed'
return `${req.method} completed`
},
// Define a custom receive message
customReceivedMessage: function (req, _res) {
customReceivedMessage: function (req, res) {
return 'request received: ' + req.method

@@ -175,5 +175,6 @@ },

// Define a custom error message
customErrorMessage: function (error, res) {
customErrorMessage: function (req, res, err) {
return 'request errored with status code: ' + res.statusCode
},
// Override attribute keys for the log object

@@ -188,3 +189,3 @@ customAttributeKeys: {

// Define additional custom request properties
customProps: function (req,res) {
customProps: function (req, res) {
return {

@@ -191,0 +192,0 @@ customProp: req.customProp,

@@ -137,3 +137,3 @@ 'use strict'

const logger = pinoHttp({
customLogLevel: function (_res, _err, _req) {
customLogLevel: function (_req, _res, _err) {
return 'warn'

@@ -159,3 +159,3 @@ }

{
customLogLevel: function (_res, _err, _req) {
customLogLevel: function (_req, _res, _err) {
return 'silent'

@@ -185,3 +185,3 @@ }

const logger = pinoHttp({
customLogLevel: function (_res, _err, _req) {
customLogLevel: function (_req, _res, _err) {
return 'error-log-level'

@@ -208,3 +208,3 @@ }

useLevel: 'info',
customLogLevel: function (_res, _err, _req) {
customLogLevel: function (_req, _res, _err) {
return 'warn'

@@ -785,4 +785,4 @@ }

const logger = pinoHttp({
customSuccessMessage: function (res) {
return customResponseMessage
customSuccessMessage: function (req, res) {
return customResponseMessage + ' ' + req.method
}

@@ -797,3 +797,3 @@ }, dest)

dest.on('data', function (line) {
t.equal(line.msg, customResponseMessage)
t.equal(line.msg, customResponseMessage + ' GET')
t.end()

@@ -852,4 +852,4 @@ })

const logger = pinoHttp({
customErrorMessage: function (err, res) {
return customErrorMessage + ' ' + err.toString()
customErrorMessage: function (req, res, err) {
return customErrorMessage + ' ' + req.method + ' ' + err.toString()
}

@@ -864,3 +864,3 @@ }, dest)

dest.on('data', function (line) {
t.equal(line.msg.indexOf(customErrorMessage), 0)
t.equal(line.msg.indexOf(customErrorMessage + ' GET'), 0)
t.end()

@@ -978,3 +978,3 @@ })

const logger = pinoHttp({
reqCustomProps: customPropsHandler
customProps: customPropsHandler
}, dest)

@@ -1005,3 +1005,3 @@

const logger = pinoHttp({
reqCustomProps: customPropsHandler
customProps: customPropsHandler
}, dest)

@@ -1028,3 +1028,3 @@

},
reqCustomProps: (req, res) => {
customProps: (req, res) => {
return {

@@ -1031,0 +1031,0 @@ key1: 'value1',

Sorry, the diff of this file is not supported yet

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