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(), or uologging.add_verbosity_flag(parser):

import uologging
import argparse

# Option 1
parser = argparse.ArgumentParser(parents=[uologging.get_default_parser()])
# Option 2
# uologging.add_verbosity_flag(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.2.0.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file uologging-0.2.0.tar.gz.

File metadata

  • Download URL: uologging-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.6

File hashes

Hashes for uologging-0.2.0.tar.gz
Algorithm Hash digest
SHA256 08a3a19ad5adeef153c3d37c5966ffaae89631f57dfbe8ba47662a44fd9838f6
MD5 fb30efcdc3fd8861bbc29135851dba13
BLAKE2b-256 41a26b383ca52e79f1cb23a051eedafc1890d313d4a661583cb214f995ab0278

See more details on using hashes here.

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