A logging level, or severity, classifies messages by importance and controls which details a logging system emits or stores. Keep critical events visible while limiting routine diagnostic volume. section 4.2.2
Use levels to match message volume with investigative value:
- Error marks critical issues that should always be logged, such as unhandled Java exceptions. section 4.2.2
- Warn marks potentially failed events that the application handled, such as a third-party call succeeding after a retry. section 4.2.2
- Info records common execution events that explain normal application behavior. section 4.2.2
- Debug records fine-grained details and should usually remain disabled until normal messages are insufficient for an investigation. section 4.2.2
Changing the diagnostic detail
A Java StringDigitExtractor logs the extraction start and result at info, while logging each parsed character at debug. With the root logger set to info, output shows only the start and result. Changing the Log4j configuration to debug adds one message for every character, revealing the method's fine-grained execution. section 4.2.2
Treat the level as part of a larger logging path: a logger selects messages, an appender stores or sends them, and a formatter shapes their output. Different deployments can use different thresholds. Avoid logging inside large loops unless a condition narrows the iterations, and change verbosity without restarting the service when the framework permits it. section 4.2.2 section 4.2.3
For garbage-collection logs, selective levels such as error or warning reduce retained data; file rotation also limits storage and makes investigation easier. section 11.3
Figure 4.12 The log severity pyramid. On the top are the critical log messages that usually require immediate attention. The bottom represents the log messages that provide details you’ll rarely need. From the top to the bottom, the log messages become less essential but greater in number. Usually, the debug-level messages are disabled by default, and the developer can choose to enable them if their investigation requires fine-grained details about the app’s execution.
The severity pyramid makes the trade-off visible: messages become more numerous and less essential toward the debug level. section 4.2.2








