Skip to main content

Small library for printing warnings and creating logs.

Project description

mylogging

PyPI pyversions PyPI version Language grade: Python Build Status License: MIT codecov

My python logging module not only for new python libraries. Based on debug value prints warnings and errors. It's automatically colorized. It can be logged to file if configured (then color ignored).

Documentation does not exists, because it's such a small project, that it's not necessary - everything important is in this readme (and in the docstrings for developers).

Motivation for this project is to create simplest logging module that do everytthing I need.

Example

import mylogging

# We can define whether to
#   display warnings: debug=1,
#   ignore warnings: debug=0,
#   stop warnings as errors: debug=3

mylogging.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
mylogging.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:
    mylogging.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 string that we can use...

print(mylogger.user_message("I will be printed anyway"))

# If you want to log to file, just add the path (with log suffix) on the beginning

mylogging._TO_FILE = "path/to/my/file.log"

This is the result of the upper snippet

Plot of results

If colors are not wanted (resulting weird symbols) you can use this after the import

mylogging._COLORIZE = 0  # Turn off colorization on all functions

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

mylogging-1.1.2.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distributions

mylogging-1.1.2-py3.7.egg (12.4 kB view hashes)

Uploaded Source

mylogging-1.1.2-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

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