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 logging is enabled for a category, it is also enabled for all of its subcategories
  • If logging is enabled for a specific severity level, then it's also enabled for all the higher severity levels

Examples:

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" );
   try
   {
      ...
   }
   finally
   {
      Log.getNDC().pop();
   }
}

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.