Log level parameter type for Click
Project description
GitHub | PyPI | Issues | Changelog
click-loglevel provides a LogLevel parameter type for use in Click programs that wish to let the user set the logging level. It accepts all of the logging log level names (CRITICAL, ERROR, WARNING, INFO, DEBUG, and NOTSET, all case insensitive), and converts them into their corresponding numeric values. It also accepts integer values and leaves them as-is.
Installation
click-loglevel requires Python 3.6 or higher. Just use pip for Python 3 (You have pip, right?) to install click-loglevel and its dependencies:
python3 -m pip install click-loglevel
Example
myscript.py:
import logging
import click
from click_loglevel import LogLevel
@click.command()
@click.option("-l", "--log-level", type=LogLevel(), default=logging.INFO)
def main(log_level):
logging.basicConfig(
format="%(asctime)s [%(levelname)-8s] %(name)s %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S%z",
level=log_level,
)
...
Running myscript.py:
$ python3 myscript.py --log-level DEBUG
# Log level is set to "DEBUG"
$ python3 myscript.py --log-level error
# Log level is set to "ERROR"
$ python3 myscript.py --log-level 15
# Log level is between DEBUG and INFO
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
click-loglevel-0.2.0.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for click_loglevel-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d7e9b94a2f0f274ca5598357cba89faa9269b14be10ae12a8524bf2359e7d0 |
|
MD5 | e40b6f55a38d892c714b9b3493a08acb |
|
BLAKE2b-256 | 9e5f1789f632f296549a97c24316d718b196783baf25305d0176cfaa87cb2efe |