Skip to main content

A package for easy verbose logging, error and warnings.

Project description

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.

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

papagei-niederha-0.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

papagei_niederha-0.0.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file papagei-niederha-0.0.2.tar.gz.

File metadata

  • Download URL: papagei-niederha-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for papagei-niederha-0.0.2.tar.gz
Algorithm Hash digest
SHA256 52b23821a847365a9c444b97b102cfb602c5159c2956f2748d2610aa8492ac37
MD5 49572d20f882738a8924e8792030b50e
BLAKE2b-256 7d444e6e2ffab50c354735ef3d19dcba54f5fdf7dfe99be35034aa846761dd26

See more details on using hashes here.

File details

Details for the file papagei_niederha-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: papagei_niederha-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for papagei_niederha-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09d3c6fd06d5a429976da8ae5864b0c4c28affeab0f03dac47c7ad3f07032b33
MD5 faab08462252e5874735fba13af25531
BLAKE2b-256 c7c43ae9d063f084fde7af8bc519fae07434740a5a8b6b9433a96d7b511bf7e5

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