From 860a2141228b98803e2ef793f0dbab13613890e0 Mon Sep 17 00:00:00 2001 From: Adam Brauer <400763+ambrauer@users.noreply.github.com> Date: Mon, 12 Apr 2021 15:42:05 -0500 Subject: [PATCH] Added DEBUG_MULTILINE to allow switching from %o (pretty-print single line) to %O (pretty-print multiple line) formatting (#649) --- .../troubleshooting/debug-logging/en.md | 2 ++ packages/sitecore-jss/src/debug.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/data/routes/docs/fundamentals/troubleshooting/debug-logging/en.md b/docs/data/routes/docs/fundamentals/troubleshooting/debug-logging/en.md index bcb69074b2..5acb357369 100644 --- a/docs/data/routes/docs/fundamentals/troubleshooting/debug-logging/en.md +++ b/docs/data/routes/docs/fundamentals/troubleshooting/debug-logging/en.md @@ -52,8 +52,10 @@ When running through Node.js, you can set a few additional environment variables | Name | Purpose | | --- | --- | | `DEBUG` | Enables/disables specific debugging namespaces. | +| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). Default is `false`. | | `DEBUG_COLORS` | Whether or not to use colors in the debug output. Default is `true`. | | `DEBUG_DEPTH` | Object inspection depth. Default is `2`. | +| `DEBUG_MULTILINE` | Pretty-print inspected objects on multiple lines. Default is `false` (single line). | | `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. Default is `false`. | > To learn more about the `DEBUG_` environment variables, see [debug](https://www.npmjs.com/package/debug#environment-variables). \ No newline at end of file diff --git a/packages/sitecore-jss/src/debug.ts b/packages/sitecore-jss/src/debug.ts index 62e5424905..ae49c1059b 100644 --- a/packages/sitecore-jss/src/debug.ts +++ b/packages/sitecore-jss/src/debug.ts @@ -1,9 +1,22 @@ import debug from 'debug'; +import { isServer } from './util'; const rootNamespace = 'sitecore-jss'; export type Debugger = debug.Debugger; +// On server/node side, allow switching from the built-in +// `%o` (pretty-print single line) and `%O` (pretty-print multiple line) +// with a `DEBUG_MULTILINE` environment variable. +if ( + isServer() && + process?.env?.DEBUG_MULTILINE === 'true' && + debug.formatters.o && + debug.formatters.O +) { + debug.formatters.o = debug.formatters.O; +} + /** * Default Sitecore JSS 'debug' module debuggers. Uses namespace prefix 'sitecore-jss:'. * See {@link https://www.npmjs.com/package/debug} for details.