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]
Metadata
Release files for echolog 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| echolog-0.0.5.tar.gz | 6.1 kB | Without provenance | Details for echolog-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| echolog-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for echolog-0.0.5-py3-none-any.whl |
Total release size: 13.6 kB
Release files / echolog-0.0.5.tar.gz
| Download URL | echolog-0.0.5.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30cb51118267a254f4c427b3afdc3e10adecd1357c9e9420cc16269fdf6aedaf
|
|
BLAKE2b-256 checksum How to use checksums |
a71ec844cf1784c6ecad559bd97a373e184f6b1762e228e819752a4eb536370e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.12
|
Release files / echolog-0.0.5-py3-none-any.whl
| Download URL | echolog-0.0.5-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
03e3221846a08e0dfd0ab5a8f8ae799dacf0f56379815c368d3c655bfe7a66a1
|
|
BLAKE2b-256 checksum How to use checksums |
8420effa1319efd9ea8086e7363bf99e51705a49bda09df82c5c1993672f2015
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.12
|
Security for echolog 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.