Skip to content

Commit

Permalink
trace_events: respect inspect() depth
Browse files Browse the repository at this point in the history
This commit causes the Tracing class to account for
util.inspect() depth.

PR-URL: #28037
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
cjihrig authored and BridgeAR committed Jun 17, 2019
1 parent 2331e9c commit 9dd840d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/trace_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Tracing {
}

[customInspectSymbol](depth, opts) {
if (typeof depth === 'number' && depth < 0)
return this;

const obj = {
enabled: this.enabled,
categories: this.categories
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2497,3 +2497,15 @@ assert.strictEqual(
assert(i < 2 || line.startsWith('\u001b[90m'));
});
}

{
// Tracing class respects inspect depth.
try {
const trace = require('trace_events').createTracing({ categories: ['fo'] });
const actual = util.inspect({ trace }, { depth: 0 });
assert.strictEqual(actual, '{ trace: [Tracing] }');
} catch (err) {
if (err.code !== 'ERR_TRACE_EVENTS_UNAVAILABLE')
throw err;
}
}

0 comments on commit 9dd840d

Please sign in to comment.