Logging in Storefront Next
Storefront Next includes a built-in structured logger that outputs JSON to stdout. The logger automatically enriches each log entry with a correlation ID and request context, making requests easy to trace across your application and search in Log Center.
Use getLogger(context) to get a request-scoped logger. It automatically includes the correlation ID, HTTP method, and path in every log entry.
Use createLogger() when router context isn’t available, such as in client-side code or utility functions.
Pass an optional metadata object as the second argument to any log method. Metadata fields are included as JSON properties in the log output.
The logger automatically serializes error instances with name, message, and stack fields.
Storefront Next supports four log levels, from most to least severe:
| Level | Use for |
|---|---|
error | Unrecoverable failures within a request |
warn | Recoverable problems: fallback paths, retries, degraded behavior |
info | Observable outcomes: request completed, action succeeded/failed, state changes |
debug | Internal progress: intermediate steps, useful for local debugging |
On Managed Runtime, configure the log level in your environment settings:
- Log in to Runtime Admin.
- Click your project, then your target environment.
- Click Environment Settings.
- In the Advanced section, set the Log Level.
- Click Update and wait for the bundle to redeploy.
Alternatively, set the log level via the Managed Runtime API. Call projects_target_partial_update with "log_level" in the payload.
For local development, use the SFCC_LOG_LEVEL environment variable:
| Value | Logs emitted |
|---|---|
error | error only |
warn | error + warn |
info | error + warn + info |
debug | all messages |
| (not set) | warn in production, info otherwise |
In production, logs are output as structured JSON (ndjson). Each entry contains:
| Field | Description |
|---|---|
level | Log severity: error, warn, info, or debug |
msg | The log message |
correlationId | A unique ID for tracing a request across log entries |
method | HTTP method (GET, POST, etc.) |
path | URL pathname of the request |
Example:
In development, logs are pretty-printed with colors and timestamps for readability.
Every incoming request is assigned a correlation ID — either extracted from the x-correlation-id request header or generated automatically. All log entries for that request share the same correlationId, which lets you trace a single request end to end.
Log Center lets you search and filter production logs from Managed Runtime and your B2C Commerce instance.
To access MRT logs in Log Center:
- Have the Log Center User role in Account Manager. If you don’t have the role, ask your Account Manager admin to give you access.
- Set up your MRT environment:
- Mark the environment as a production environment.
- Select a B2C Commerce instance to connect to the environment.
- Add one or more site IDs to associate with the environment.
MRT logs in Log Center are available only for production environments. There can be a delay of up to 15 minutes between an event and the log appearing in Log Center.
- Start Log Center.
- Select a Region and Realm.
- Click Show filtered results.
- Click Search > Current Search.
- Under Service Type, select mrt.
- Under Request Type, select SSR for application logs or CDN for CDN logs.
- Under Host, select your production environment (
$PROJECT.$ENVIRONMENT).
Use the correlationId field to filter all log entries for a single request.
- Each MRT log message is limited to 32 KB. Characters beyond 32 KB are truncated.
- For information about log levels and log volumes, see Configuration for Administrators.