Patterns for Logging Diagnostic Messages

By: N.B. Harrison
Published in: PLoPD3
Pages: 277-289
Category: Communications, Telecommunications, Transaction Processing

Summary: Transaction-oriented systems lend themselves to common approaches to logging diagnostic messages.

Pattern: Diagnostic Logger

Pages: 278-281

To report diagnostic information in a consistent manner, use a diagnostic logger as a single point for all messages to flow through. The diagnostic logger has two functions: (1) control of logging in general, e.g., specifying the output destination, error thresholds, debugging levels; and (2) other functions that allow the rest of the system to output diagnostic messages.

Pattern: Diagnostic Context

Pages: 281-285

You're using Diagnostic Logger. If an error occurs in processing a set of discrete inputs, to associate error messages with the responsible input, while a transaction is processed, a diagnostic object identifies the transaction. The diagnostic logger will associate the error message with the context information in the associated diagnostic context.

Pattern: Typed diagnostics

Pages: 285-288

You're using Diagnostic Context and logging many different messages (e.g., errors, warnings, debugging messages). To be sure they are handled consistently, create an inheritance hierarchy of diagnostic message types. Each type encapsulates the characteristics of that category of diagnostics and parameterizes the variations. Details of diagnostic messages are embedded in the classes.