Skip to main content

Utility lib logging, statistics, subprocesses

Project description

Name

libsrg -- count calls to python logging at each logging severity level

Description

libsrg provides the following classes:

  • libsrg.LoggingCounter
    • extends logging.Handler with count of logs at each severity level
    • counts on output, so logs suppressed by current logging level do not get counted
    • atexit hook used to print statistics on program exit
  • libsrg.LoggingAppBase
    • application base class with LoggingCounter installed
    • argparse.ArgumentParser
      • --verbose sets logging level to DEBUG
      • --logfile directs logging to a file
    • Derived classes can add application specific options to ArgumentParser
  • libsrg.Runner
    • run command line in a subprocess
    • capture stdout, stderr
    • try catch block for exceptions
    • exceptions can optionally be raised back to calling program

I write a lot of smallish command line utilities for internal use, and factored out some common repetitive boilerplate code into this package. Published for my own installation convenience, but might be useful to others as well.

Example output

Library uses atexit hook to summarize logging activity counts and total execution time. Counts are also available to the program at runtime.

2022-02-22 12:46:22,568 INFO     (libsrg.LoggingCounter:61) __log_atexit 
Logging Summary:
Logging at Level INFO       occurred         13 times
Logging at Level DEBUG      occurred          1 times
Logging at Level WARNING    occurred          1 times
Logging at Level ERROR      occurred          2 times
Logging at Level CRITICAL   occurred          1 times
Elapsed time was 0.087 seconds

Internal notes on updating

  • /GNAS/PROJ/PycharmProjects/libsrg/publish.bash
#! /bin/bash

cd /GNAS/PROJ/PycharmProjects/libsrg
rm -rf dist
python3 -m build --wheel
python3 -m twine check dist/*
python3 -m twine upload dist/*

Installation from pypi via pip

  • pip3 install libsrg
  • pip3 install libsrg --update

Installation from Gitlab or local repository

  • pip3 install git+ssh://git@gitlab.com/SRG_gitlab/libsrg.git
  • pip3 install /GNAS/PROJ/PycharmProjects/libsrg

Testing

Pytest performs its own logging setup before calling any user supplied tests, so it doesn't work well testing these classes logging setup. Ad-hoc test code is supplied at the end of the classes and executes if the class is loaded as main.

Roadmap

My intention is to keep this library small. It is not expected to evolve into an all-purpose framework. Output is geared towards developers, not end users.

License

MIT

Project status

Pulled extraneous applications out into libsrg_apps

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

libsrg-5.3.0.tar.gz (74.7 kB view details)

Uploaded Source

Built Distribution

libsrg-5.3.0-py3-none-any.whl (55.1 kB view details)

Uploaded Python 3

File details

Details for the file libsrg-5.3.0.tar.gz.

File metadata

  • Download URL: libsrg-5.3.0.tar.gz
  • Upload date:
  • Size: 74.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.4 Linux/6.6.36-200.fc40.x86_64

File hashes

Hashes for libsrg-5.3.0.tar.gz
Algorithm Hash digest
SHA256 e5b67555221a6fca3b1975ab7e87bef7a7f225320769e7934f2283eeb959c553
MD5 9ab35bc630e8d4d40a2d764d13df9365
BLAKE2b-256 5a59cd44bf22fc5a2dd274ffa102d7363d32f5b15518f93e9b063de6c02860b8

See more details on using hashes here.

File details

Details for the file libsrg-5.3.0-py3-none-any.whl.

File metadata

  • Download URL: libsrg-5.3.0-py3-none-any.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.4 Linux/6.6.36-200.fc40.x86_64

File hashes

Hashes for libsrg-5.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e56ad693921fd6e6b787591d27996c12f34a1f4d616f5c14c242a27dbb4ef270
MD5 72277d112e84b021c1fbc682f923a8d1
BLAKE2b-256 8f867604eec7fcf0470b2da424a43c228e6036aee0f92642734caea3e773bb03

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