Skip to main content

Auto-Configuration solution for Python built-in logging.

Project description

uologging is a solution for configuring Python's built-in logging module.

A full example is provided in the docstring for uologging.init_console_logging().

Configuring logging via uologging

The verbosity_flag can be gathered via argparse using uologging.get_default_parser():

import uologging
import argparse
parser = argparse.ArgumentParser(parents=[uologging.get_default_parser()])
args = parser.parse_args(['-vv'])

Now, call uologging.init_console_logging() with that verbosity_flag for YOUR package:

uologging.init_console_logging(mypackage, args.verbosity_flag)

Default Log Level

Per Python logging suggestion: WARNING, ERROR, and CRITICAL messages are all logged by default. Meanwhile, INFO and DEBUG messages can be enabled by providing verbosity_flag of 1 or 2 to uologging.init_console_logging().

logging Best Practices

Use the Python logging package per the following best practices:

  • logger = logging.getLogger(__name__) to get the logger for each module/script.
  • Use logger.debug(), logger.info(), logger.warning(), etc to add tracing to your modules/packages/scripts.

A trivial example demonstrating best practices:

# hello.py
import logging

logger = logging.getLogger(__name__)

def hello():
    logger.debug('About to say "hello!"')
    print('hello!')
    logger.debug('Said "hello!"')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uologging-0.1.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page