Small library for printing warnings and creating logs.
Project description
mylogging
My python logging module. Based on debug value prints warnings and errors. It's automatically colorized. It can be logged to file if configured.
Documentation does not exists, because it's such a small project, that it's not necessary.
Motivation for this project is, that i need this functionallity in each project, so to not repeat myself.
Example
from mylogging import mylogger
# We can define whether to
# display warnings: debug=1,
# ignore warnings: debug=0,
# stop warnings as errors: debug=3
mylogger.set_warnings(debug=1, ignored_warnings=["invalid value encountered in sqrt",
"encountered in double_scalars"])
# We can create warning that will be displayed based on warning settings
mylogger.user_warning('Hessian matrix copmputation failed for example', caption="RuntimeError on model x")
# In case we don't know exact error reason, we can use traceback_warning in try/except block
try:
u = 10 / 0
except Exception:
mylogger.traceback_warning("Maybe try to use something different than 0")
# In case we don't want to warn, but we have error that should be printed anyway and not based on warning settings, we can use user_message that return extended that we can use...
mylogger.user_message("I will be printed anyway")
This is the result of the upper snippet
If you want to log warnings into text file or it will be printed for example on some CI log console, colors will be probably changed into unwanted symbols. For such a cases you can use this after the import
mylogger._COLORIZE = 0 # Turn off colorization on all functions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mylogging-1.0.26-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50379e49a50ed9cbb5eb01e3ae1e39cccafbde8b23e8e9424c10a06e40fe7c67 |
|
MD5 | f5dac7d8e30b2227ce049151a130e279 |
|
BLAKE2b-256 | dd3d946432a4f6f6530a6ef3f5cdffd21461899556b8c4f68ee674c25de8b43d |