-
Notifications
You must be signed in to change notification settings - Fork 845
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
Fix max-depth using safe-stable-stringify #1169
Conversation
lib/tools.js
Outdated
@@ -29,6 +29,14 @@ const { | |||
const { isMainThread } = require('worker_threads') | |||
const transport = require('./transport') | |||
|
|||
let stringifySafe |
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.
This should not be a global configuration but a per-base-logger one.
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.
Matteo already commented. Also, if we're introducing new options they need to be documented
package.json
Outdated
@@ -101,6 +101,8 @@ | |||
"winston": "^3.3.3" | |||
}, | |||
"dependencies": { | |||
"@types/estree": "^0.0.50", | |||
"@types/json-schema": "^7.0.9", |
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.
please remove those types
docs updated
@@ -95,6 +95,17 @@ const logger = pino({ | |||
logger.foo('hi') | |||
logger.info('hello') // Will throw an error saying info in not found in logger object | |||
``` | |||
#### `depthLimit` (Number) | |||
|
|||
Default: `5` |
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.
Are these defaults ok? I did some tests on my machine and this seemed to be a reasonable default
const stream = sink() | ||
const root = pino(stream) | ||
// circular depth | ||
const obj = {} | ||
obj.a = obj | ||
root.info(obj) | ||
const { a } = await once(stream, 'data') | ||
same(a, { a: '[Circular ~]' }) | ||
same(a, { a: '[Circular]' }) |
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.
Another tests for non circular objects would be good:
const obj = {}
let parent = obj
for (let i = 0; i < 20; i++) {
parent.node = {}
parent = parent.node
}
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 have added another test for non circular objects
docs/api.md
Outdated
|
||
Default: `5` | ||
|
||
Option to limit stringification at a specific nesting depth |
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.
Option to limit stringification at a specific nesting depth | |
Option to limit stringification at a specific nesting depth when logging circular object. |
docs/api.md
Outdated
|
||
Default: `100` | ||
|
||
Option to limit stringification of properties for a specific object |
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.
Option to limit stringification of properties for a specific object | |
Option to limit stringification of properties for a specific object when logging circular objects. |
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.
note this is not only about objects properties, but it also limits the number of elements in arrays
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.
Looks good to me with suggestions applied.
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.
lgtm
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.
lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR uses
safe-stable-stringify
library to limit the depth/breadth when serializing the objectRefs: #1120, #1121
Closes: #990
Note: This PR relies on BridgeAR/safe-stable-stringify#22