liveBook · Manning

Logging level

As explained in Troubleshooting Java, Second Edition

A logging level is a configuration category that controls the severity or amount of messages emitted or stored by a logging system.

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

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains four common severities, demonstrates Log4j thresholds, and extends the idea to GC retention and rotation.
Examples
Uses a Java digit extractor, Log4j XML configurations, severity-filtered output, and GC file-rotation commands.
What it assumes
Assumes basic Java application logging and introduces severity categories, framework configuration, and investigative trade-offs.
What you can do after
Configure Log4j and GC logging to increase diagnostic detail selectively while controlling message volume and storage.
How it connects
Connects logging levels with logging frameworks, loggers, appenders, formatters, and garbage-collection logs.

Also explained in

Compare how 9 books explain logging level →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.