Skip to content
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

Merged
merged 9 commits into from
Oct 26, 2021

Conversation

sameer-coder
Copy link
Contributor

@sameer-coder sameer-coder commented Oct 18, 2021

This PR uses safe-stable-stringify library to limit the depth/breadth when serializing the object

Refs: #1120, #1121

Closes: #990

Note: This PR relies on BridgeAR/safe-stable-stringify#22

@sameer-coder sameer-coder marked this pull request as ready for review October 18, 2021 12:27
lib/tools.js Outdated
@@ -29,6 +29,14 @@ const {
const { isMainThread } = require('worker_threads')
const transport = require('./transport')

let stringifySafe
Copy link
Member

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.

Copy link
Contributor

@simoneb simoneb left a 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

@sameer-coder sameer-coder marked this pull request as draft October 18, 2021 17:44
package.json Outdated
@@ -101,6 +101,8 @@
"winston": "^3.3.3"
},
"dependencies": {
"@types/estree": "^0.0.50",
"@types/json-schema": "^7.0.9",
Copy link
Member

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
@sameer-coder sameer-coder marked this pull request as ready for review October 19, 2021 05:54
@sameer-coder
Copy link
Contributor Author

sameer-coder commented Oct 19, 2021

@Matteo @simoneb I have updated the code as per the feedback, updated the docs, and fixed tests. The build is failing because the v2.0.1 of the safe-stable-stringify package isn't published yet. The open PR is here. Please review.

@@ -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`
Copy link
Contributor Author

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]' })
Copy link
Member

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
}

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Option to limit stringification of properties for a specific object
Option to limit stringification of properties for a specific object when logging circular objects.

Copy link
Contributor

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

Copy link
Member

@jsumners jsumners left a 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.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit f16c98d into pinojs:master Oct 26, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CPU Hang with infinite decirc
5 participants