Debugging

Salesforce Interactions SDK provides an in-built logger that outputs messages to the browser console for debugging purposes. This logger wraps the standard browser console.log function and is accessible via SalesforceInteractions.log.

By default, the SDK is configured with a logging level of none (0), meaning the logger doesn't output messages until you explicitly configure a higher logging level.

The logging level controls the verbosity of the debug output. Setting a log level displays all messages at that level and any lower levels. For example, setting the level to warn (2) will also display error (1) messages.

LevelValueDescription
trace5Used for finer-grained, highly-detailed informational messages than debug.
debug4Used for fine-grained messages during development and debugging.
info3Used for standard informational messages about the SDK's operation.
warn2Used to surface potential issues with the Web SDK that can affect functionality.
error1Used for error events that indicate the Web SDK isn’t functioning properly.
none0Default. Disables all logging output.

Use this method to change the SDK's logging level.

You can use either use the name of the logging level or the numeric value.

Use this method to return the numeric value of the current logging level used by the SDK.

Here's an example of how you can use the getLoggingLevel() method.

Use the SalesforceInteractions.log object to output your own custom messages from your site's code. These messages will only appear in the browser console if the SDK's configured logging level is set to match or exceed the level of the method you call.

MethodLevelDescriptionExample
log.trace(...args: any[]): void5 (Highest)Prints a message at the trace level.SalesforceInteractions.log.trace("Deep trace details.")
log.debug(...args: any[]): void4Prints a message at the debug level.SalesforceInteractions.log.debug("Hello!")
log.info(...args: any[]): void3Prints a message at the info level.SalesforceInteractions.log.info("Sitemap initialization complete.")
log.warn(...args: any[]): void2Prints a message at the warn level.SalesforceInteractions.log.warn("Missing optional user attribute: phone number.")
log.error(...args: any[]): void1 (Lowest)Prints a message at the error level.SalesforceInteractions.log.error("An API call failed during checkout.")