Log categories for script loggers and category level inheritance
Key Takeaway
A category with no active rule of its own uses the level of the nearest category above it that has one. Rules pass down to subcategories only. They don't pass up to a parent or across to a sibling.
In B2C Commerce, your scripts write custom log messages under named log categories, such as product or product.import. Rules in Business Manager decide which severity levels each category actually records. Categories form a dot-separated tree under a root category, so one rule on a parent category can control logging for all of its subcategories.
Log categories in code
In a script, you write custom log messages through a logger for a named category.
var log = Logger.getLogger("order.send"); // => dw.system.Log object for "order.send"
log.warn("Order export is slow");
log.error("Order export failed");The Logger.getLogger() method on the dw.system.Logger class takes a category name and returns a dw.system.Log object for that category. You then call its debug, info, warn, error or fatal method to write a message, as the last two lines do. The model is similar to Log4J2.
Category names are hierarchical, and the dots set the levels. For example, product.import is a subcategory of product. Every category is a subcategory of the root category. You get the root logger with Logger.getRootLogger().
In code, a category name must contain only alphanumeric characters and dots. Salesforce recommends planning a simple naming hierarchy before you create categories, such as names that include the script, object and method. A planned hierarchy makes code maintenance easier.