Logger API: custom log files and levels
How to write script logging with dw.system.Logger and Log: category loggers versus custom named files, static methods versus logger instances, MessageFormat arguments, enabled-level guards, which level reaches a file, redundancy suppression and keeping sensitive data out of logs.
Given a logging task and existing configuration, write code that logs non-sensitive data to custom log files with different log levels.
~7 min read · 10 practice questions ·
What the exam expects
- Obtain a logger for a category or for a custom named log file, and predict which file the messages land in when several scripts use the same prefix.
- Choose between the static
Loggermethods and aLoginstance, including for fatal messages. - Write messages with MessageFormat placeholders and guard expensive debug output with the instance's enabled check.
- Pick the log level that reaches a file given the existing Custom Log Settings and notification requirements.
- Explain gaps caused by redundancy suppression, read the custom error log for controller exceptions, and keep sensitive data out of logs, including service communication logs.
Key terms: category (the name a logger is configured by in Custom Log Settings); file name prefix (the first getLogger argument that creates a custom named log file); Log (the log4j-like logger instance the getters return); MessageFormat (the Java {0} placeholder syntax the logging methods implement); redundancy tracking (suppression of error and warn messages repeated too often).
Key facts
- Detail
- Same log instance, same log file
- Detail
- Business Manager custom log categories also apply
- Detail
- 3 to 25 characters
- Detail
- 200 per day per appserver (Web Services page says 40); then
getLoggerthrows
- Detail
debug,info,warn,error; no staticfatal
- Detail
- Always enabled; optional email
- Detail
- Java MessageFormat,
{0},{1}
customwarn- Detail
- Always logged to file
- Detail
- Always disabled
- Detail
- Over 10 in 3 minutes: suppressed 3 minutes
- Detail
- Function hierarchy and line numbers, for developers
- Detail
- Not enabled; warning in the import log
Sources for this section (5)
- What does
Log.getNDC()return? - When does a new suppression period start after one has ended?
- Why can't
_renewalsbe used as a file name prefix? - Which three
Loggermethods return aLoginstance?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the B2C Commerce Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the B2C Commerce Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Practice exams purchase adds inline bank questions and topic practice (10 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Choose guide-only, practice-only, or save $4 with both