Skip to main content

A logging package that adds an echo() function to return both the input expression/variable and its results. Also sets up nicely-formatted logging.

Project description

echolog

A logging package that adds an "echo" function to return both the input expression/variable and its results. Also sets up nicely-formatted logging.

Utilities

(function) echo(**args, **kwargs)

A printing function intended largely for debugging. 
For all passed args/kwargs, it prints both the expression passed to it (in plaintext, as written in the IDE)
and the value that expression/variable evaluates to.

(function) get_logger(level=None, fmt=None, id=None)

Sets up a custom logger.

Parameters
----------
level : int or str or None
    Logging level.
    default: logging.ECHO
fmt : str
    One of the following strings, defining the logging format:
    'short', 'short-time', 'long', 'long-time'
    default: short-time
id : str or None
    ID to use to identify the new logger. If None, it instead modifies the logging module's root logger.
    default: None
    
Returns
-------
logger : logging.Logger
    The created logger (or root logger, if id=None).

(function) newline(n=1)

Prints n newlines, if and only if the current logging level is lower than logging.INFO.

Parameters
----------
n : int
    Number of newlines to print.
    default: 1

Returns
-------
    None

(dict/DotMap) C

Dictionary including the ANSI color codes for the following colors:

['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray']

Abbreviations for the colors also work:
['k', 'r', 'g', 'y', 'b', 'm', 'c', 'w', 'gy']

Adding 'bg_' to the start of any of these will get the background ANSI color.

Finally, 'reset' contains the ANSI code to reset to default formatting.

Example usage

Running the main echolog.py project file directly the following test case:

    newline(3)
    
    for fmt in ['short-time', 'short', 'long-time', 'long']:
        log = get_logger(level=logging.DEBUG, fmt=fmt)

        echo(       f"Demo echo() call with   fmt={fmt}")
        log.debug(  f'Demo debug message with fmt = {fmt}.')
        log.debug(  f'Demo debug message with fmt = {fmt}.')
        log.echo(   f'Demo echo message with  fmt = {fmt}.')
        log.info(   f'Demo info message with  fmt = {fmt}.')
        log.warning(f'Demo warn message with  fmt = {fmt}.')
        log.error(  f'Demo error message with fmt = {fmt}.')
        log.fatal(  f'Demo fatal message with fmt = {fmt}.')
    
        newline()
    
    a = 2
    b = [3, 4]

    echo('Example call to echo() with multiple arguments.', a, blah=b)
    newline()

You should probably run this on your own machine to best demonstrate, as Github does not support color text formatting in README files. Without colors, though, the output should look something like this:

    17:14:07.923 [>] echolog.py @ line 311:                 f"Demo echo() call with   fmt={fmt}" => Demo echo() call with   fmt=short-time
    17:14:07.937 [/] Demo debug message with fmt = short-time.
    17:14:07.937 [/] Demo debug message with fmt = short-time.
    17:14:07.944 [>] Demo echo message with  fmt = short-time.
    17:14:07.944 [-] Demo info message with  fmt = short-time.
    17:14:07.944 [!] Demo warn message with  fmt = short-time.
    17:14:07.944 [x] Demo error message with fmt = short-time.
    17:14:07.949 [X] Demo fatal message with fmt = short-time.

    [>] echolog.py @ line 311:              f"Demo echo() call with   fmt={fmt}" => Demo echo() call with   fmt=short
    [/] Demo debug message with fmt = short.
    [/] Demo debug message with fmt = short.
    [>] Demo echo message with  fmt = short.
    [-] Demo info message with  fmt = short.
    [!] Demo warn message with  fmt = short.
    [x] Demo error message with fmt = short.
    [X] Demo fatal message with fmt = short.

    [17:14:07.965  ECHO] echolog.py @ line 311:             f"Demo echo() call with   fmt={fmt}" => Demo echo() call with   fmt=long-time
    [17:14:07.973 DEBUG] Demo debug message with fmt = long-time.
    [17:14:07.981 DEBUG] Demo debug message with fmt = long-time.
    [17:14:07.981  ECHO] Demo echo message with  fmt = long-time.
    [17:14:07.981  INFO] Demo info message with  fmt = long-time.
    [17:14:07.981  WARN] Demo warn message with  fmt = long-time.
    [17:14:07.981 ERROR] Demo error message with fmt = long-time.
    [17:14:07.989 FATAL] Demo fatal message with fmt = long-time.

     [ECHO] echolog.py @ line 311:          f"Demo echo() call with   fmt={fmt}" => Demo echo() call with   fmt=long
    [DEBUG] Demo debug message with fmt = long.
    [DEBUG] Demo debug message with fmt = long.
     [ECHO] Demo echo message with  fmt = long.
     [INFO] Demo info message with  fmt = long.
     [WARN] Demo warn message with  fmt = long.
     [ERROR] Demo error message with fmt = long.
    [FATAL] Demo fatal message with fmt = long.

     [ECHO] echolog.py @ line 325:   'Example call to echo() with multiple arguments.' => Example call to echo() with multiple arguments.
     [ECHO] echolog.py @ line 325:   a => 2
     [ECHO] echolog.py @ line 325:   blah => [3, 4]

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

echolog-0.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

echolog-0.0.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file echolog-0.0.2.tar.gz.

File metadata

  • Download URL: echolog-0.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for echolog-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c0a3e30938c6a640cba139e371b1c06802d0655d1711331e5f29be40e677e290
MD5 009f5db6b8871bf351ce594b55ad8d4b
BLAKE2b-256 82ecc4af5c84f69a39d8d03f2ca6231e51f05a74b7921954e2f742aa63d505b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: echolog-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for echolog-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 59b89bba2f9d1b0bcc44272833f0f99bdc42c54aa8c54a2df44031ef8a85283e
MD5 71201fde891afbb55198088d3d25e028
BLAKE2b-256 6e9294c57754d0fb6019ef558f6d0aa165452a3feb723f4cef8868cc3ff48efb

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