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

Create depth limit option for the log line #1121

Closed
mcollina opened this issue Sep 8, 2021 · 6 comments
Closed

Create depth limit option for the log line #1121

mcollina opened this issue Sep 8, 2021 · 6 comments

Comments

@mcollina
Copy link
Member

mcollina commented Sep 8, 2021

As titled.

Previous ones #990 #1120

@leorossi
Copy link
Contributor

I am working on this, if I read it correctly this code

const pino = require("pino")({ maxDepth: 3 });
const o = { a: { b: { c: { d: { e: { f: 'foobar' } } } } } }
pino.info(o)

would produce something like this: {"a":{"b":{"c":"[...]"}}}

I am currently testing with this code

const pino = require("pino")();
const nested = {};
const MAX_DEPTH = 10 * 784;
let currentNestedObject = null;
for (let i = 0; i < MAX_DEPTH; i++) {
  const k = 'nest_' + i;
  if (!currentNestedObject) {
    currentNestedObject = nested;
  }
  currentNestedObject[k] = {};
  currentNestedObject = currentNestedObject[k];
}
pino.info(nested);

This is a very edge-case, a deeply nested object which is like this: { nest_0: { nest_1: { nest_2: {...} } } }

We reach immediately this line which calls JSON.stringify which does not support a max-depth feature.

In fact with that big MAX_DEPTH, it raises a RangeError: Maximum call stack size exceeded.

The same error is raised by the next catch block which tries json-stringifys-safe.

At this point the only way I see it is to parse the object and change it to removes all the keys at nesting level > MAX_DEPTH, before passing to the write function.

Is this the correct approach?

@mcollina
Copy link
Member Author

At this point the only way I see it is to parse the object and change it to removes all the keys at nesting level > MAX_DEPTH, before passing to the write function.

Is this the correct approach?

Not really. Essentially we should embed json-stringify-safe and implement this feature there.

@runk
Copy link
Contributor

runk commented Nov 3, 2021

I've had the same issue, however mostly around the size of the log and into how much money it translates. Been using https://github.com/runk/dtrim for quite some time - it covers all scenarios where you'd expect huge amounts of data to be logged: array, nested objects, buffers, big strings. Would be nice to see it used in pino, or have similar functionality for truncating lengthy structures.

@Fdawgs
Copy link
Member

Fdawgs commented May 29, 2023

@mcollina did #1169 resolve this?

@mcollina
Copy link
Member Author

yes good catch!

@github-actions
Copy link

This issue 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 Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants