-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(serializers): avoid implicit sanitization #2081
base: main
Are you sure you want to change the base?
Changes from 5 commits
651d194
a3b1681
f8c5c31
bbbecc3
054993b
aaa51ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
/* eslint no-prototype-builtins: 0 */ | ||
|
||
const format = require('quick-format-unescaped') | ||
const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers') | ||
const SonicBoom = require('sonic-boom') | ||
const onExit = require('on-exit-leak-free') | ||
const { | ||
|
@@ -21,6 +20,8 @@ const { | |
formattersSym, | ||
messageKeySym, | ||
errorKeySym, | ||
requestKeySym, | ||
responseKeySym, | ||
nestedKeyStrSym, | ||
msgPrefixSym | ||
} = require('./symbols') | ||
|
@@ -40,13 +41,6 @@ function genLog (level, hook) { | |
function LOG (o, ...n) { | ||
if (typeof o === 'object') { | ||
let msg = o | ||
if (o !== null) { | ||
if (o.method && o.headers && o.socket) { | ||
o = mapHttpRequest(o) | ||
} else if (typeof o.setHeader === 'function') { | ||
o = mapHttpResponse(o) | ||
} | ||
} | ||
let formatParams | ||
if (msg === null && n.length === 0) { | ||
formatParams = [null] | ||
|
@@ -113,6 +107,8 @@ function asJson (obj, msg, num, time) { | |
const formatters = this[formattersSym] | ||
const messageKey = this[messageKeySym] | ||
const errorKey = this[errorKeySym] | ||
const responseKey = this[responseKeySym] | ||
const requestKey = this[requestKeySym] | ||
let data = this[lsCacheSym][num] + time | ||
|
||
// we need the child bindings added to the output first so instance logged | ||
|
@@ -132,6 +128,10 @@ function asJson (obj, msg, num, time) { | |
value = serializers[key](value) | ||
} else if (key === errorKey && serializers.err) { | ||
value = serializers.err(value) | ||
} else if (key === requestKey && serializers.req) { | ||
value = serializers.req(value) | ||
} else if (key === responseKey && serializers.res) { | ||
value = serializers.res(value) | ||
Comment on lines
+131
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behaviour of all |
||
} | ||
|
||
const stringifier = stringifiers[key] || wildcardStringifier | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,6 +408,14 @@ declare namespace pino { | |
* The string key for the 'error' in the JSON object. Default: "err". | ||
*/ | ||
errorKey?: string; | ||
/** | ||
* The string key for the 'Request' in the JSON object. Default: "req". | ||
*/ | ||
requestKey?: string; | ||
/** | ||
* The string key for the 'Response' in the JSON object. Default: "res". | ||
*/ | ||
responseKey?: string; | ||
Comment on lines
+411
to
+418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key for request and response are now explicitly configurable. Previously, these had fixed values, set on pino-std-serializers (mapHttpRequest and mapHttpResponse). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this change makes the exported functions |
||
/** | ||
* The string key to place any logged object under. | ||
*/ | ||
|
@@ -741,6 +749,8 @@ declare namespace pino { | |
readonly formatOptsSym: unique symbol; | ||
readonly messageKeySym: unique symbol; | ||
readonly errorKeySym: unique symbol; | ||
readonly responseKeySym: unique symbol; | ||
readonly requestKeySym: unique symbol; | ||
readonly nestedKeySym: unique symbol; | ||
readonly wildcardFirstSym: unique symbol; | ||
readonly needsMetadataGsym: unique symbol; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If preferred, we can assess type from properties, as previously done in
lib/tools.js
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think property presence will be better here. These could be extended objects, e.g. a
FastifyRequest
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done