Skip to content

Commit

Permalink
Added DEBUG_MULTILINE to allow switching from %o (pretty-print single…
Browse files Browse the repository at this point in the history
… line) to %O (pretty-print multiple line) formatting (#649)
  • Loading branch information
ambrauer authored Apr 12, 2021
1 parent ef3c3ed commit 860a214
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
13 changes: 13 additions & 0 deletions packages/sitecore-jss/src/debug.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 860a214

Please sign in to comment.