Skip to main content

Easy context prefixes for messages.

Project description

The primary facility here is Pfx, a context manager which manitains 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 line, lineno 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.

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

cs.pfx-20170903.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file cs.pfx-20170903.tar.gz.

File metadata

  • Download URL: cs.pfx-20170903.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cs.pfx-20170903.tar.gz
Algorithm Hash digest
SHA256 91ada24ecba2d40455d1e8bb06116372fd5ee5a7c8182ac358369df26ee2e576
MD5 20ede7c41e99ac903254dd12815af171
BLAKE2b-256 5870d950022630e60b58501e14f7d1200a9ded4518b088a3cab3c83e162df3ce

See more details on using hashes here.

Supported by

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