Design considerations and trade-offs

The logging module supports auditability and debugging ability, as well as some security requirements. We can use logging as a simple way to keep records of the processing steps. By selectively enabling and disabling logging, we can support developers who are trying to learn what the code is really doing when processing real-world data.

The warnings module supports the debugging ability as well as maintainability features. We can use warnings to alert developers about API problems, configuration problems, and other potential sources of bugs.

When working with the logging module, we'll often be creating large numbers of distinct loggers that feed a few handlers. We can use the hierarchical nature of Logger names to introduce new or specialized collections of logging messages. There's no reason why a class can't have two loggers: one for audit and one for more general-purpose debugging.

We can introduce new logging level numbers, but this should be done reluctantly. Levels tend to conflate developer focus (debug, info, and warning) with user focus (info, error, and fatal). There's a kind of spectrum of optionality from debug messages that is not required for fatal error messages, which should never be silenced. We might add a level for verbose information or possibly detailed debugging, but that's about all that should be done with levels.

The logging module allows us to provide a number of configuration files for different purposes. As developers, we may use a configuration file that sets the logging levels to DEBUG and enables specific loggers for modules under development. For final deployment, we can provide a configuration file that sets the logging levels to INFO and provides different handlers to support more formal audit or security review needs.

We'll include some thoughts from The Zen of Python (https://www.python.org/dev/peps/pep-0020/):

"Errors should never pass silently.
Unless explicitly silenced."

The warnings and logging modules directly support this idea.

These modules are oriented more toward overall quality than toward the specific solution of a problem. They allow us to provide consistency via fairly simple programming. As our object-oriented designs become larger and more complex, we can focus more on the problem being solved without wasting time on the infrastructure considerations. Further, these modules allow us to tailor the output to provide information needed by the developer or user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset