Skip to main content

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

Download files

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

Source Distribution

libsrg-26.8.1.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libsrg-26.8.1-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: libsrg-26.8.1.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for libsrg-26.8.1.tar.gz
Algorithm Hash digest
SHA256 0bf92f1602ff93220bf6e5dbd7bc88c69678e35e90de5edb01fa5a08978a6540
MD5 8a11df504f8ae9c7d6b42745b14cc2ab
BLAKE2b-256 a7d8cf85b1726f7980d7ae7d916de98e89438737094afd2fee7c8f710d50c249

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libsrg-26.8.1-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.27

File hashes

Hashes for libsrg-26.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d43a5af0204a6ea46640b8431f380feee97b339463e90368147d4e9684dc873b
MD5 32c847c6faed18c0445871e3ff39fcfe
BLAKE2b-256 c0b74c13798fbf4163cf95cdd5ba5bd691ea2729d8f8513afb841bff33e2f0d4

See more details on using hashes here.

Release history Release notifications | RSS feed

26.9.2

2 files

26.9.1

2 files

26.8.2

2 files

This release

26.8.1 This release

2 files

26.8.0

2 files

6.2.2

2 files

6.2.1

2 files

6.2.0

2 files

6.1.0

2 files

6.0.4

2 files

6.0.3

2 files

6.0.2

2 files

6.0.1

2 files

6.0.0

2 files

5.3.0

2 files

5.2.3

2 files

5.2.2

2 files

5.2.1

2 files

5.2.0

2 files

5.1.1

2 files

5.1.0

2 files

5.0.0

2 files

4.4.1

2 files

4.4.0

2 files

4.3.2

1 file

4.3.1

1 file

4.3.0

1 file

4.2.3

1 file

4.2.2

1 file

4.2.1

1 file

4.2.0

1 file

4.1.5

1 file

4.1.4

1 file

4.1.3

1 file

4.1.2

1 file

4.1.1

1 file

4.1.0

1 file

4.0.5

1 file

4.0.4

1 file

4.0.3

1 file

4.0.2

1 file

4.0.1

1 file

4.0.0

1 file

3.8.6

1 file

3.8.5

1 file

3.8.4

1 file

3.8.3

1 file

3.8.2

1 file

3.8.1

1 file

3.8.0

1 file

3.7.7

1 file

3.7.6

1 file

3.7.5

1 file

3.7.4

1 file

3.7.3

1 file

3.7.2

1 file

3.7.1

1 file

3.7.0

1 file

3.6.4

1 file

3.6.3

1 file

3.6.2

1 file

3.6.1

1 file

3.5.2

1 file

3.5.1

1 file

3.5.0

1 file

3.4.7

1 file

3.4.6

1 file

3.4.5

1 file

3.4.4

1 file

3.4.3

1 file

3.4.2

1 file

3.4.1

1 file

3.4.0

1 file

3.3.5

1 file

3.3.4

1 file

3.3.3

1 file

3.3.2

1 file

3.3.1

1 file

3.3.0

1 file

3.2.2

1 file

3.2.1

1 file

3.2.0

1 file

3.1.4

1 file

3.1.3

1 file

3.1.2

1 file

3.1.1

1 file

3.0.5

1 file

3.0.4

1 file

3.0.3

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.1.6

1 file

2.1.5

1 file

2.1.4

1 file

2.1.3

1 file

2.1.2

1 file

2.1.1

1 file

2.1.0

1 file

2.0.6

1 file

2.0.5

1 file

2.0.3

1 file

2.0.2

1 file

2.0.1

1 file

2.0.0

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

1 file

1.3.0

1 file

1.2.5

1 file

1.2.4

1 file

1.2.3

1 file

1.2.2

1 file

1.2.1

1 file

1.2.0

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

0.9.4

1 file

0.9.3

1 file

0.9.2

1 file

0.9.1

1 file

0.9.0

1 file

0.1.1

1 file

0.1.0

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