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 demo.py executes the following test case:

    import logging
    from echolog import echo, get_logger, newline
    
    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.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

echolog-0.0.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: echolog-0.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 30cb51118267a254f4c427b3afdc3e10adecd1357c9e9420cc16269fdf6aedaf
MD5 1963f3810c0b706ae2ba85388b2d3176
BLAKE2b-256 a71ec844cf1784c6ecad559bd97a373e184f6b1762e228e819752a4eb536370e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: echolog-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 03e3221846a08e0dfd0ab5a8f8ae799dacf0f56379815c368d3c655bfe7a66a1
MD5 9932cd8e38cc38b1b85b2cf272fe8e44
BLAKE2b-256 8420effa1319efd9ea8086e7363bf99e51705a49bda09df82c5c1993672f2015

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