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

Easy context prefixes for messages.

Project Description

The primary facility here is Pfx, a context manager which maintains a per thread stack of context prefixes. Usage is like this:

from cs.pfx import Pfx
...
def parser(filename):
  with Pfx("parse(%r)", filename):
    with open(filename) as f:
      for lineno, line in enumerate(f, 1):
        with Pfx("%d", lineno) as P:
          if line_is_invalid(line):
            raise ValueError("problem!")
          P.info("line = %r", line)

This produces log messages like:

datafile: 1: line = 'foo\n'

and exception messages like:

datafile: 17: problem!

which lets one put just the relevant complaint in exception and log messages and get useful calling context on the output. This does make for wordier logs and exceptions but used with a little discretion produces far more debugable results.

Release History

This version
History Node

20170903.1

History Node

20170903

Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
cs.pfx-20170903.1.tar.gz
(4.7 kB) Copy SHA256 Hash SHA256
Source None Sep 3, 2017

Supported By

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 Google Google Cloud Servers DreamHost DreamHost Log Hosting