Skip to main content

Log level parameter type for Click

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status https://codecov.io/gh/jwodder/click-loglevel/branch/master/graph/badge.svg https://img.shields.io/pypi/pyversions/click-loglevel.svg MIT License

GitHub | PyPI | Issues

click-loglevel provides a LogLevelType 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 LogLevelType

@click.command()
@click.option("-l", "--log-level", type=LogLevelType(), 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


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.1.0.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

click_loglevel-0.1.0-py3-none-any.whl (4.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