Debug logging in JSS apps

Version:

Sitecore JSS NPM packages and samples use the debug module for printing out debugging information.

The module exposes the debug() function, an augmented version of console.log() statements. Unlike console.log, you do not have to comment out or remove debug() calls in production code, which means you can easily enable debug logs in production when necessary using environment variables.

All Sitecore JSS logs are organized under the root namespace sitecore-jss. Logging is turned off by default and can be conditionally turned on by using the DEBUG environment variable.

Note

The debug logs only include server-side code, so there is no benefit to enabling debug logging in the browser.

To output all debug logs available, set the DEBUG environment variable to sitecore-jss:*. The asterisk * is used as a wildcard.

DEBUG=sitecore-jss:*

You can be selective and show only a specific category of log messages, for example, layout service logs.

DEBUG=sitecore-jss:layout

Alternatively, you can show all but layout service logs by using the - prefix:

DEBUG=sitecore-jss:*,-sitecore-jss:layout

Namespaces

The following table lists all the available namespaces, along with the applicable Sitecore JSS npm packages and sample applications.

NamespacePackage(s) / sample app(s)Description
sitecore-jss:httpsitecore-jss, nextjsHTTP request and response logging for default fetch wrappers (GraphQLRequestClient and AxiosDataFetcher).
sitecore-jss:dictionarysitecore-jss, nextjs, node-headless-ssr-experience-edgeTrace logging for dictionary service implementations (GraphQLDictionaryService and RestDictionaryService).
sitecore-jss:layoutsitecore-jss, nextjs, node-headless-ssr-experience-edgeTrace logging for layout service implementations (GraphQLLayoutService and RestLayoutService).
sitecore-jss:editingsitecore-jss-nextjs, nextjsTrace logging for Next.js middleware for Sitecore editor integration.
sitecore-jss:sitemapsitecore-jss-nextjs, nextjsTrace logging for Next.js GraphQL sitemap service (GraphQLSitemapService).

Advanced options

When running through Node.js, you can set a few additional environment variables that change the behavior of the debug logging by using the following environment variables:

NameDescription
DEBUGEnables/disables specific debugging namespaces.
DEBUG_HIDE_DATEHide date from debug output (non-TTY). Default is false.
DEBUG_COLORSWhether or not to use colors in the debug output. Default is true.
DEBUG_DEPTHObject inspection depth. Default is 2.
DEBUG_MULTILINEPretty-print inspected objects on multiple lines. Default is false (single line).
DEBUG_SHOW_HIDDENShows hidden properties on inspected objects. Default is false.
If you have suggestions for improving this article, let us know!