Salesforce B2C Commerce 20.9 > Developing Your Site > Development Components > Scripts > Script Programming > Understanding Server-Side JavaScript

Custom Log Categories

B2C Commerce logging supports log categories in a way that is similar to Log4J2 (a Java-based logging utility supported by Apache Software Foundation). A log category is basically a name, where a dot in the name is interpreted as a hierarchical structure. For example, the log category "product.import" would be a subcategory of "product". All categories are subcategories of a "root" category.

B2C Commerce's category rules are:


If... Then...
Logging is enabled for "product" It's also enabled for "product.import"
logging is enabled for the root logger It's enabled for all custom log categories
WARN logging is enabled for "product" WARN and ERROR are logged for "product" and all its subcategories
WARN logging is enabled for "product" and DEBUG for "product.import" WARN and ERROR are logged for "product" and all its subcategories, for the subcategory "product.import" also DEBUG and INFO are logged.

Example: :

function sendOrder() {
   var logger = Logger.getLogger( "order.send" );
   logger.debug( "Sending order #{}", order.getOrderNumber() );

NDC Support

With Nested Diagnostic Context (NDC), the application can provide more context information, which is associated with the current running thread. A simple string can be provided as NDC, which is organized like a stack. Both the NDC and log category are reported as a standard element of the actual log message. The following example shows how to use this feature.

function process() {
   Log.getNDC().push( "order.processing" );

Message Format

Message formatting supports a simple '{}' for inserting an argument. The method is tolerant if more argument placeholders are provided then arguments exist. In that case, the placeholder isn't replaced but remains a '{}'.

For backwards compatibility, B2C Commerce also supports Java message formatting.

X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.