colored logging to terminal for CLI scripts
Project description
write out messages with various levels: INFO, ERROR, etc...
Description
This module provides a routine to write out a message of various levels such as DEBUG, INFO, WARNING, ERROR and CRITICAL. The messages are high-lighted with different colors if they are going to a terminal. If the output has been redirected to a file, then the colors are turned off. You can also specify to not use colors at all.
Levels DEBUG and INFO go to stdout, while WARNING, ERROR and CRITICAL go to stderr.
Messages for level DEBUG will only be printed if the 1st optional argument debug is set to True.
The second argument (progname) is an optional program name to be printed at the beginning of the message provided.
The third argument (use_color) is an optional program name to control whether to use color on the message level or not. default is True.
Code example
import os
import sys
import argparse
import logging
from cli_logging_moxad import setup_cli_logging
# check for options --debug and --nocolor
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", action="store_true",
help="Enable debug logging")
parser.add_argument("-n", "--nocolor", action="store_false",
help="Disable color output")
args = parser.parse_args()
setup_cli_logging(debug=args.debug,
progname=os.path.basename( sys.argv[0]),
use_color=args.nocolor,
)
logging.debug("Debug message")
logging.info("Info message")
logging.warning("This is a warning!")
logging.error("This is an ERROR!")
logging.critical("Critical issue!!!")
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cli_logging_moxad-0.7.0.tar.gz.
File metadata
- Download URL: cli_logging_moxad-0.7.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d1f75538a97174a2bd6836534e05a19f9a5df5bea0a43716b58ff48efc49416
|
|
| MD5 |
da6ff2ea9766789348c6da25e1ede778
|
|
| BLAKE2b-256 |
3b3ff711ed65e561cf24473e5b48cd6fb7ba157ac9be0cf9a91c2d163df6eae9
|
File details
Details for the file cli_logging_moxad-0.7.0-py2.py3-none-any.whl.
File metadata
- Download URL: cli_logging_moxad-0.7.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
500aaf8f3cd66a61378a6341942b9e550fd032d37dd7681006d6904ea32ce55a
|
|
| MD5 |
7d6ac245813f6809a01b83d35641c073
|
|
| BLAKE2b-256 |
8d52107cdc75ed89ad9644283003115382a5fbbbb127ff80ce6c571db6ccfbea
|