From c40229a9b80736f1fdb31fac169b70a1d6af8669 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 17 Aug 2017 22:41:14 -0700 Subject: [PATCH] console: implement minimal `console.group()` Node.js exposes `console.group()` and `console.groupEnd()` via the inspector. These functions have no apparent effect when called from Node.js without the inspector. We cannot easily hide them when Node.js is started without the inspector because we support opening the inspector during runtime via `inspector.port()`. Implement a minimal `console.group()`/`console.groupEnd()`. More sophisticated implementations are possible, but they can be done in userland and/or features can be added to this at a later time. `console.groupCollapsed()` is implemented as an alias for `console.group()`. PR-URL: https://github.com/nodejs/node/pull/14910 Fixes: https://github.com/nodejs/node/issues/1716 Ref: https://github.com/nodejs/node/issues/12675 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Timothy Gu Reviewed-By: Anna Henningsen --- doc/api/console.md | 27 +++++++ lib/console.js | 24 +++++- test/parallel/test-console-group.js | 111 ++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-console-group.js diff --git a/doc/api/console.md b/doc/api/console.md index 08fcfa027c7bad..ee130d7b9714b7 100644 --- a/doc/api/console.md +++ b/doc/api/console.md @@ -286,6 +286,32 @@ If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`][] is called on each argument and the resulting string values are concatenated. See [`util.format()`][] for more information. +### console.group([...label]) + + +* `label` {any} + +Increases indentation of subsequent lines by two spaces. + +If one or more `label`s are provided, those are printed first without the +additional indentation. + +### console.groupCollapsed() + + +An alias for [`console.group()`][]. + +### console.groupEnd() + + +Decreases indentation of subsequent lines by two spaces. + ### console.info([data][, ...args])