Debug logging in Content SDK apps
Sitecore Content SDK NPM packages and sample applications use the debug module for displaying debugging information.
This module exposes the debug() function, an augmented version of console.log(). Unlike console.log(), you don't have to comment or remove debug() calls in production code, which means you can easily configure debug logs in production using environment variables, as needed.
All Content SDK logs are organized under the root namespace content-sdk. Logging is turned off by default, but it can be conditionally enabled using the DEBUG environment variable. There are also several related environment variables that you can use to further configure the content and appearance of debug logs.
When logging is enabled and you run your application, for example with npm run start:production, all triggered instances of debug() relevant to the namespaces you choose to include will be displayed in your console.
The debug logs only include server-side code, so there is no reason to enable debug logging in the browser.
To output all available debug logs, set the DEBUG environment variable to content-sdk:*. The asterisk behaves as a wildcard.
DEBUG=content-sdk:*You can use namespaces to selectively show a specific category of log messages, for example, layout service logs.
DEBUG=content-sdk:layoutTo include more than one specific log namespace, you can write the namespaces in a comma-separated list. The following example will cause debug logs to only include layout and dictionary service logs:
DEBUG=content-sdk:layout,content-sdk:dictionaryTo include everything except for specific logs, you can follow the wildcard namespace with a comma-separated list of namespaces that you want to exclude. In the following example, the logs will return everything except for layout service logs, which are excluded due to the - prefix:
DEBUG=content-sdk:*,-content-sdk:layoutNamespaces
The following table lists all the namespaces available for debug logging in Content SDK apps.
|
Namespace |
Description |
|---|---|
|
|
HTTP request and response logging for default fetch wrappers. |
|
|
Trace logging for the dictionary service. |
|
|
Trace logging for the layout service. |
|
|
Trace logging for SitecoreAI editor integration. |
|
|
Trace logging for the sitemap service. |
|
|
Trace logging for the robots.txt service. |
|
|
Trace logging for the |
|
|
Trace logging for the error pages service. |
|
|
Trace logging for the site info service and Next.js multisite middleware. |
|
|
Trace logging for the personalize service and Next.js personalize middleware. |
|
|
Common logging messages used throughout the application. |
|
|
Trace logging for the search service. |
Advanced options
When using Node.js, you can change the behavior of debug logging by using any of the following optional environment variables:
|
Name |
Description |
|---|---|
|
|
boolean Whether to hide dates from debug output (non-TTY only). default: |
|
|
boolean Whether to use colors in the debug output. default: |
|
|
number The object inspection depth. default: |
|
|
boolean Whether to pretty-print inspected objects on multiple lines. If not, they are displayed on a single line. default: |
|
|
boolean Whether to show hidden properties on inspected objects. default: |