Skip to main content

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))
  setup_logging(cmd)

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)", foo.name):
    [...]
    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.

Download files

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

Source Distribution

cs.logutils-20160827.tar.gz (9.6 kB view details)

Uploaded Source

File details

Details for the file cs.logutils-20160827.tar.gz.

File metadata

File hashes

Hashes for cs.logutils-20160827.tar.gz
Algorithm Hash digest
SHA256 ff7239d6ea8db141f4adfdb2d8b332b8b5c07e9c963a101fd4a807c19a136234
MD5 c3db9e6b6a101301f16a3fc33f74cd39
BLAKE2b-256 5351c3a69f8a099061c32ee46f67c1acf187e529a5982e34a9ad261e7c29b14c

See more details on using hashes here.

Release history Release notifications | RSS feed

20250323

2 files

20250306

2 files

20241109

2 files

20241007

2 files

20240923

2 files

20240630

2 files

20230212

2 files

20220531

2 files

20220530

2 files

20220315

1 file

20220227

1 file

20211208

1 file

20210721

1 file

20210718

1 file

20210306

1 file

20201021

1 file

20200729

1 file

20200613

1 file

20200519

1 file

20200518

1 file

20200229

1 file

20190923

1 file

20190220

1 file

20190103

1 file

20190101

1 file

20171030

1 file

20160828

1 file

This release

20160827 This release

1 file

20150118

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page