Skip to main content

PAPAGEI

Papagei is a module that proposes an implementation for verbose logging. Python has options to do verbose logging, error warning and error handling and so on. However, multiple packages are often implied and implementing the desired messages might require multiple lines of code. Papagei is an attempt to make a module that allows to do verbose logging in a simple way without importing multiple packages imports and with a minimal number of lines of code for each call. Despite being fairly simple, papagei has the downside of being more rigid. It is good for simple cases and debug. For more complex error handling or message formatting you might want to get back to python built in functions and packages.

Using papagei

There are three major components in papagei:

  • VerboseLevel(Enum) (class)
  • VERBOSE (object of type VerboseLevel)
  • The display functions

VerboseLevel and verbose:

In this implementation papagei has 6 verbose levels:

  • SILENT: Nothing will be displayed no errors will be raised no warnings will be returned.
  • ERROR: Only mock_errors() are displayed. errors are raised as usual.
  • WARNINGS: Errors behave as usual, and warnings and mock_warnings as well.
  • INFO: All messages from the previous levels plus the info messages.
  • DEBUG: All messages from the previous levels plus the debug messages.
  • FRIVOLOUS: All messages from the previous levels plus the frivolity messages.

The verbose level can be set using the VERBOSE variable and the VerboseLevel enum. For example:

VERBOSE = VerboseLevel.INFO

NOTE: Due to its simple implementation the verbose level in papagei only works on the functions form the papagei packages. In other words putting papagei.VERBOSE to silent will not silence errors raised outside of the papagei package, won't implement any warning filter to cancel out warnings from outside of the papapgei module and won't obliterate any print() done outside of the papagei module.

Functions

All functions are link to a specific debug level. Two functions are available for the ERROR level and the WARNING level. One uses the actual python warnings and error the other one (preceded by "mock_") only print a message in the console without interrupting the run of the program.

  • error(*args): (Level: ERROR) Formats the args into a string and uses it to raise an error.
  • mock_error(*args): (Level: ERROR) Formats the args into a string and prints them in an error-like format.
  • warning(*args, **kwargs): (Level: WARNING) Formats the args into a string and uses it to generate a warning. The warning type can be changed by passing a Waring class through the key-word 'type'. The warning is displayed and the warning object is returned by the function.
  • mock_warning(*args): (Level: WARNING) Formats the args into a string and displays it into a warning-like format.
  • info(*args): (Level: INFO) Formats the args into a string and displays it into a specific info-format.
  • debug(*args): (Level: DEBUG) Formats the args into a string and displays it into a specific debug-format.
  • frivolity(*args): (Level: FRIVOLOUS) Formats the args into a string and displays it into a specific frivolity-format.

Example

from papagei import papagei as ppg
ppg.VERBOSE = ppg.VerboseLevel.DEBUG

ppg.debug('This is example', 1)  # This message will show
ppg.frivolity('This is example', 2)  # This won't show

NOTE: The import statement has a slight redundancy in it. This should be fixed later.

Modifying the source code

Even if it is not possible to add classes from outside of the package, the source code was made in a way that should make the adding, removing, moving or reformatting class easy.

Reformatting a class

The formatting of a class is done through the text_format dictionary. The value of the dictionary is added before each string of the corresponding level to format it. Chang the value in this dictionary to change the formats. Same goes for the text_header dictionary which displays a header at the beginning of a message.

Adding, removing or moving a class

To move a class in the hierarchy all that has to be done it to change its position in the VerboseLevel(Enum) enum. This enum is auto-numbered so moving it will adapt the value of the item and the checks in every functions will be adapted. To add an item the corresponding VerboseLevel should be added in the enum. Then the text_format and text_header dictionaries should be updated. Finally a dedicated function for the new level can be written on the model debug, info or frivolity, using _format_string_from_tuple(string_tuple) to format *args into a single string. Same process can be followed in reverse to remove a class.

Metadata

Release files for papagei-niederha 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for papagei-niederha 0.0.2
File Size Uploaded
papagei-niederha-0.0.2.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for papagei-niederha 0.0.2
File Interpreter ABI Platform
papagei_niederha-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / papagei-niederha-0.0.2.tar.gz

Download URL papagei-niederha-0.0.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
52b23821a847365a9c444b97b102cfb602c5159c2956f2748d2610aa8492ac37
BLAKE2b-256 checksum
How to use checksums
7d444e6e2ffab50c354735ef3d19dcba54f5fdf7dfe99be35034aa846761dd26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.4

Release files / papagei_niederha-0.0.2-py3-none-any.whl

Download URL papagei_niederha-0.0.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09d3c6fd06d5a429976da8ae5864b0c4c28affeab0f03dac47c7ad3f07032b33
BLAKE2b-256 checksum
How to use checksums
c7c43ae9d063f084fde7af8bc519fae07434740a5a8b6b9433a96d7b511bf7e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.4

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

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