Skip to main content

colored log messages and banners from commandline and python

Project description

lib_log_utils

Version v1.4.14.2 as of 2022-06-02 see Changelog

build_badge license jupyter pypi PyPI - Downloads black

codecov better_code Maintainability Maintainability Code Coverage snyk

this library makes it easy to log colored messages from python and from the commandline. Text Wrapping is supported.

whenever possible, it tries to autodetect the correct settings for colored output.

currently the settings for TRAVIS and BINDER/Jupyter are detected automatically


automated tests, Travis Matrix, Documentation, Badges, etc. are managed with PizzaCutter (cookiecutter on steroids)

Python version required: 3.6.0 or newer

tested on recent linux with python 3.6, 3.7, 3.8, 3.9, 3.10, pypy-3.8 - architectures: amd64

good code coverage, flake8 style checking ,mypy static type checking ,tested under Linux, macOS, Windows, automatic daily builds and monitoring



Try it Online

You might try it right away in Jupyter Notebook by using the “launch binder” badge, or click here

Usage

Python

import the module and check the code - it is very easy and documented there

as soon as I have some time, this will be completed (help welcome)

Commandline

Usage:

     log_util (-h | --version | --program_info)
     log_util [Options] "<message>"
     log_util "<message>" [Options]

Options:
     -h, --help          show help
     --version           show version
     --program_info      show Program Info

Arguments

message

the message to log

Options

option

description

-l –level <level>

the log level as number or predefined value, default = INFO

-b –banner

log as banner

-w –width <width>

the width of the message or the banner, if text wrap is used, default = 140

-s –silent <True|False> **

disables the output if set to “True” (not case sensitive)**, default = False

-q –quiet

disables the output (as flag), default = False

-f –force

take precedence over environment settings, default = False

–wrap –nowrap

use text wrap (this is the default value), default = True

–traceback –no-traceback

show traceback on commandline error, default = False

-e –extended

extended log format, default = plain

-p –plain

plain log format, default = plain

-c –colortest

color test

**This makes it possible to silence messages elegantly in a shellscript:

 #!/bin/bash

 # disable deprecation messages
 DEP_MSG_OFF="True"

...
...
log_util -l warning "some deprecation message" --silent=${DEP_MSG_OFF}
log_util -l info "another deprecation message" --silent=${DEP_MSG_OFF}
...

log levels

Text

Integer

NOTSET

0

SPAM

5

DEBUG

10

VERBOSE

15

INFO

20

NOTICE

25

WARNING

30

SUCCESS

35

ERROR

40

CRITICAL

50

Environment Settings

environment variable

function

LOG_UTIL_FMT

the log format - either “plain”, “extended” or a custom formatting string, default = plain

LOG_UTIL_LEVEL

the level of the logger, one of the predefined log levels, or “0” - “50”, default = 0

LOG_UTIL_WIDTH

the banner width if text wrap is used, must be >=”10”, default = 140

LOG_UTIL_WRAP

if text wrap should be used, must be True or False (not case sensitive), default = True

LOG_UTIL_QUIET

if the logger is used at all - must be True or False (not case sensitive), default = False

COLOREDLOGS_LOG_FORMAT

as described in coloredlogs

COLOREDLOGS_DATE_FORMAT

as described in coloredlogs

COLOREDLOGS_FIELD_STYLES

as described in coloredlogs

COLOREDLOGS_LEVEL_STYLES

as described in coloredlogs

environment settings take precedence over commandline arguments, unless –force is passed to the commandline

EXAMPLES

# multi-line banner
log_util -l warning "Line1${IFS}Line2${IFS}Line3"

# only show log messages from level WARNING upwards
export LOG_UTIL_LEVEL=WARNING

log_util -l info   "spam"   # this is not shown
log_util -l error  "ham"    # this is shown

# reset the log_level to 0 (the default value)
unset LOG_UTIL_LEVEL

Usage from Commandline

Usage: log_util [OPTIONS] [MESSAGE]

  colored log messages and banners from commandline and python

Options:
  --version                     Show the version and exit.
  -e, --extended                extended log format
  -p, --plain                   plain log format
  -b, --banner                  log as banner
  -w, --width INTEGER           wrap width, default=140
  --wrap / --nowrap             wrap text
  -s, --silent TEXT             disable logging if "True"
  -q, --quiet                   disable logging as flag
  -f, --force                   take precedence over environment settings
  -l, --level TEXT              log level as number or predefined Level
  --program_info                get program info
  -c, --colortest               color test
  --traceback / --no-traceback  return traceback information on cli
  -h, --help                    Show this message and exit.

Installation and Upgrade

  • Before You start, its highly recommended to update pip and setup tools:

python -m pip --upgrade pip
python -m pip --upgrade setuptools
  • to install the latest release from PyPi via pip (recommended):

python -m pip install --upgrade lib_log_utils
  • to install the latest version from github via pip:

python -m pip install --upgrade git+https://github.com/bitranox/lib_log_utils.git
  • include it into Your requirements.txt:

# Insert following line in Your requirements.txt:
# for the latest Release on pypi:
lib_log_utils

# for the latest development version :
lib_log_utils @ git+https://github.com/bitranox/lib_log_utils.git

# to install and upgrade all modules mentioned in requirements.txt:
python -m pip install --upgrade -r /<path>/requirements.txt
  • to install the latest development version from source code:

# cd ~
$ git clone https://github.com/bitranox/lib_log_utils.git
$ cd lib_log_utils
python setup.py install
  • via makefile: makefiles are a very convenient way to install. Here we can do much more, like installing virtual environments, clean caches and so on.

# from Your shell's homedirectory:
$ git clone https://github.com/bitranox/lib_log_utils.git
$ cd lib_log_utils

# to run the tests:
$ make test

# to install the package
$ make install

# to clean the package
$ make clean

# uninstall the package
$ make uninstall

Requirements

following modules will be automatically installed :

## Project Requirements
click
coloredlogs
cli_exit_tools
lib_parameter
lib_platform
lib_programname

Acknowledgements

  • special thanks to “uncle bob” Robert C. Martin, especially for his books on “clean code” and “clean architecture”

Contribute

I would love for you to fork and send me pull request for this project. - please Contribute

License

This software is licensed under the MIT license

Changelog

  • new MAJOR version for incompatible API changes,

  • new MINOR version for added functionality in a backwards compatible manner

  • new PATCH version for backwards compatible bug fixes

v1.4.14.2

2022-06-02: update to github actions checkout@v3 and setup-python@v3

v1.4.14

2022-03-29: remedy mypy type error in lob_log_utils_cli

v1.4.13

2022-03-25:
  • fix ValueError: underlying buffer has been detached on github Actions Windows

  • implement github actions

  • update documentation and tests

  • list ./dist dir if existing

  • fix requirements.txt

v1.4.10

2020-10-09: service release
  • update travis build matrix for linux 3.9-dev

  • update travis build matrix (paths) for windows 3.9 / 3.10

v1.4.9

2020-08-08: service release
  • fix documentation

  • fix travis

  • deprecate pycodestyle

  • implement flake8

v1.4.8

2020-08-01: fix doctests in windows

v1.4.7

2020-08-01: fix pypi deploy

v1.4.6

2020-07-31: fix travis build

v0.4.5

2020-07-29: fix environ.pop issue in doctest

v0.4.4

2020-07-29: feature release
  • use the new pizzacutter template

v0.4.3

2020-07-27: feature release
  • use cli_exit_tools

  • add banner parameter, to temporary disable/enable banner

v0.4.2

2020-07-23: separate travis profile

v0.4.1

2020-07-23: change color profiles

v0.4.0

2020-07-23: feature release
  • correct print_exception_traceback is stdout, stderr = None

  • added formatting parameter, custom log formatter

v0.3.0

2020-07-22: feature release
  • autodetect travis settings

  • autodetect binder/jupyter settings

v0.2.0

2020-07-22: feature release
  • log_exception_traceback and print_exception_traceback will also report stdout, stderr if present

v0.1.4

2020-07-17: feature release
  • bump coverage

v0.1.3

2020-07-17: feature release
  • comprehensive –colortest

  • automatically select 8 colors profile for travis

v0.1.2

2020-07-16: feature release
  • store settings in environment for commandline use

  • cleanup

  • release on pypi

  • fix cli test

  • enable traceback option on cli errors

  • jupyter notebook

v0.1.1

2020-07-06: patch release
  • new click cli

  • use PizzaCutter Template

v0.0.2

development

v0.0.1

2019-09-03: Initial public release

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

lib_log_utils-1.4.14.2.tar.gz (22.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lib_log_utils-1.4.14.2-py3.10.egg (37.0 kB view details)

Uploaded Egg

lib_log_utils-1.4.14.2-py3.9.egg (36.8 kB view details)

Uploaded Egg

lib_log_utils-1.4.14.2-py3.8.egg (36.8 kB view details)

Uploaded Egg

lib_log_utils-1.4.14.2-py3.7.egg (36.7 kB view details)

Uploaded Egg

lib_log_utils-1.4.14.2-py3.6.egg (36.6 kB view details)

Uploaded Egg

lib_log_utils-1.4.14.2-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file lib_log_utils-1.4.14.2.tar.gz.

File metadata

  • Download URL: lib_log_utils-1.4.14.2.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for lib_log_utils-1.4.14.2.tar.gz
Algorithm Hash digest
SHA256 e860f9b36a1c6a56867f828bfe858daacd59b3306c5eea33fe86d12dedd14a11
MD5 ee768883c758d88dd907f966c68eb076
BLAKE2b-256 388025a3beb747f44387b8f8194135a94d618bd6b94b49daf7b4cbcb50d8c6e0

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3.10.egg.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3.10.egg
  • Upload date:
  • Size: 37.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for lib_log_utils-1.4.14.2-py3.10.egg
Algorithm Hash digest
SHA256 c29d7282e55122b15093e2cefdd634fe84912c7e2a98a8d838304b593cea3033
MD5 78f2c7da9fff0be9da971a8195991557
BLAKE2b-256 0fac6934128212487510b7e96d65b4f08c1d6d78aa212ed4fe43eca26af08c51

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3.9.egg.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3.9.egg
  • Upload date:
  • Size: 36.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for lib_log_utils-1.4.14.2-py3.9.egg
Algorithm Hash digest
SHA256 d93fc98be71ffe1bbd5420b7b4fc2932ef0c8b7f09c18ba5486159adf2116745
MD5 9c9c79399cbf483080c28e56496e7ef4
BLAKE2b-256 6f96fd6d0190611d73fc93a3b6e0e46b2e60eff55d79a13eeb48cc6c542a2b05

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3.8.egg.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3.8.egg
  • Upload date:
  • Size: 36.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for lib_log_utils-1.4.14.2-py3.8.egg
Algorithm Hash digest
SHA256 5df518b847dab7e8cb3e7c7a764e78ea660acde5281f73f545e9f8f5403ee6d1
MD5 bfc1c09feae14505d448dc5d40a8630f
BLAKE2b-256 f074c3ed7f5632d3d3ef715b27a3393e220c3576912705527d77b4fb46f6ab76

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3.7.egg.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3.7.egg
  • Upload date:
  • Size: 36.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.13

File hashes

Hashes for lib_log_utils-1.4.14.2-py3.7.egg
Algorithm Hash digest
SHA256 1a341c344457787b5c5bc148ec707572794b5733b3e496b21d713fd08da6fd41
MD5 81a02448ba9cd3a6736848ec4c27d91d
BLAKE2b-256 f23cec5042b5ad49c8f46a3bd321b46babcf571cf433d7114214fcb74e09adab

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3.6.egg.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3.6.egg
  • Upload date:
  • Size: 36.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for lib_log_utils-1.4.14.2-py3.6.egg
Algorithm Hash digest
SHA256 05438fb4e40888b7df691a4bc912a535bcf200d7cf3fdc9760667b07b967d133
MD5 a9ddc8d9e4d9224084c69e5e45532ab7
BLAKE2b-256 ab58f00a4f2962653d0b8b3e31762985e6a9db593302519bf17b8d78407e8112

See more details on using hashes here.

File details

Details for the file lib_log_utils-1.4.14.2-py3-none-any.whl.

File metadata

  • Download URL: lib_log_utils-1.4.14.2-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for lib_log_utils-1.4.14.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3764650405fee787355b45cf192a4cbdf8f232896147e153a7722db1741a4943
MD5 1e64bea5e215ce5558ec1758e6abdf2d
BLAKE2b-256 3ab868c20284441fd69acd1dded74a9b13471d63650dc63f0bc359b8c8d666ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page