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

[JSS] [NextJs] Debug logging multi line toggle #649

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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