Logging and tracing

All WebSphere Commerce assets can use the LoggingHelper utility class provided in the com.ibm.commerce.foundation.common.util.logging package for tracing and logging. This utility helps to resolve the Java Logger ( java.util.logging.Logger) associated with the package of the calling class. Once the Logger is resolved, the library used to log messages is java.util.logging.Logger.

The code sample below shows how to use the logger object for tracing. For more information see the Add logging and tracing to your application topic.

Note: Adding trace to the code typically results in creating new objects. You should check whether logging is enabled for our class by calling the LoggingHelper.isTraceEnabled(logger) method before calling the logging methods.

Methods which are not automatically generated should have trace entry and exit points. All trace entry statements must be matched with exit statements. Trace entry statements typically include input parameters if there are any, while exit statements include the return value(s). The entry and exit trace statements should be put inside the if-then block to check if your component trace is enabled. Below is a sample code for tracing method's entry and exit points:


Masking sensitive data in traces

There are many cases where masking sensitive data is required. WebSphere Commerce provides a MaskingFactory utility to help mask sensitive data. MaskingFactory reads a list of masking policies and parameters from the following file: workspace_dir/WC/xml/config/wc-attribute-masking.xml It is called in the following form, for example:

When it is called, it determines if and how the attributes are masked.

In the above example, MaskingFactory sees password as a parameter that is listed in the configuration file. Therefore, it returns a value of ******* instead of the abc123 value. The wc-attribute-masking.xml file contains the following elements:

Multiple masking policies can be defined in the wc-attribute-masking.xml file. For example:

There are two policies in the above example. The first policy replaces the values with 8 * characters. The second policy shows the first and last 4 digits of the value, while the rest of the value is replaced with * characters.


Related concepts
Command error handling
Execution flow tracing


Related tasks
Creating messages