Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Logging convenience routines.

Project Description

Logging convenience routines.

The logging package is very useful, but a little painful to use. This package provides low impact logging setup and some extremely useful if unconventional context hooks for logging.

The logging verbosity output format has different defaults based on whether an output log file is a tty and whether the environment variable $DEBUG is set, and to what.

Some examples:

Program initialisation:

from cs.logutils import setup_logging

def main(argv):
  cmd = os.path.basename(argv.pop(0))

Basic logging from anywhere:

from cs.logutils import info, warning, error
def some_function(...):
  error("nastiness found! bad value=%r", bad_value)

Context for log messages and exception strings:

from cs.logutils import Pfx
def func1(foo):
  with Pfx("func1(%s)",
    warning("badness!")   # emits "func1(fooname): badness!"
def loadfile(filename):
  with Pfx(filename):
    lineno = 0
    for line in open(filename):
      lineno += 1
      with Pfx("%d", lineno):
        bah = something from the line ...
        func1(bah)        # emits "filename: lineno: func1(fooname): badness!"
                          # if the warning triggers

This keeps log lines short and provides context in reported errors.

Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cs.logutils-20160828.tar.gz (10.0 kB) Copy SHA256 Checksum SHA256 Source Aug 28, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting