click-loglevel


Nameclick-loglevel JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/jwodder/click-loglevel
SummaryLog level parameter type for Click
upload_time2023-10-09 18:15:04
maintainer
docs_urlNone
authorJohn Thorvald Wodder II
requires_python>=3.7
licenseMIT
keywords cli option click command line interface log level log option logging option parsing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: http://www.repostatus.org/badges/latest/active.svg
    :target: http://www.repostatus.org/#active
    :alt: Project Status: Active — The project has reached a stable, usable
          state and is being actively developed.

.. image:: https://github.com/jwodder/click-loglevel/workflows/Test/badge.svg?branch=master
    :target: https://github.com/jwodder/click-loglevel/actions?workflow=Test
    :alt: CI Status

.. image:: https://codecov.io/gh/jwodder/click-loglevel/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/jwodder/click-loglevel

.. image:: https://img.shields.io/pypi/pyversions/click-loglevel.svg
    :target: https://pypi.org/project/click-loglevel/

.. image:: https://img.shields.io/conda/vn/conda-forge/click-loglevel.svg
    :target: https://anaconda.org/conda-forge/click-loglevel
    :alt: Conda Version

.. image:: https://img.shields.io/github/license/jwodder/click-loglevel.svg
    :target: https://opensource.org/licenses/MIT
    :alt: MIT License

`GitHub <https://github.com/jwodder/click-loglevel>`_
| `PyPI <https://pypi.org/project/click-loglevel/>`_
| `Issues <https://github.com/jwodder/click-loglevel/issues>`_
| `Changelog <https://github.com/jwodder/click-loglevel/blob/master/CHANGELOG.md>`_

``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.  Custom log levels are also supported.

Starting in version 0.4.0, shell completion of log level names (both built-in
and custom) is also supported.

.. _Click: https://palletsprojects.com/p/click/


Installation
============
``click-loglevel`` requires Python 3.7 or higher.  Just use `pip
<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install it::

    python3 -m pip install click-loglevel


Examples
========

``myscript.py``:

.. code:: python

    import logging
    import click
    from click_loglevel import LogLevel


    @click.command()
    @click.option(
        "-l",
        "--log-level",
        type=LogLevel(),
        default="INFO",
        help="Set logging level",
        show_default=True,
    )
    def main(log_level: int) -> None:
        logging.basicConfig(
            format="[%(levelname)-8s] %(message)s",
            level=log_level,
        )
        logging.log(log_level, "Log level set to %r", log_level)


    if __name__ == "__main__":
        main()

Running ``myscript.py``:

.. code:: console

    $ python3 myscript.py
    [INFO    ] Log level set to 20
    $ python3 myscript.py --log-level DEBUG
    [DEBUG   ] Log level set to 10
    $ python3 myscript.py --log-level error
    [ERROR   ] Log level set to 40
    $ python3 myscript.py --log-level 15
    [Level 15] Log level set to 15

Script with custom log levels:

.. code:: python

    import logging
    import click
    from click_loglevel import LogLevel


    logging.addLevelName(15, "VERBOSE")
    logging.addLevelName(25, "NOTICE")


    @click.command()
    @click.option(
        "-l",
        "--log-level",
        type=LogLevel(extra=["VERBOSE", "NOTICE"]),
        default="INFO",
        help="Set logging level",
        show_default=True,
    )
    def main(log_level: int) -> None:
        logging.basicConfig(
            format="[%(levelname)-8s] %(message)s",
            level=log_level,
        )
        logging.log(log_level, "Log level set to %r", log_level)


    if __name__ == "__main__":
        main()


API
===

The ``click_loglevel`` module contains a single class:

``LogLevel``
------------

A subclass of ``click.ParamType`` that accepts the standard logging level names
(case insensitive) and converts them to their corresponding numeric values.  It
also accepts integer values and leaves them as-is.

Custom log levels can be added by passing them as the ``extra`` argument to the
constructor.  ``extra`` can be either an iterable of level names (in which case
the levels must have already been defined — typically at the module level — by
calling ``logging.addLevelName()``) or a mapping from level names to their
corresponding values.  All custom log levels will be recognized case
insensitively; if two different level names differ only in case, the result is
undefined.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jwodder/click-loglevel",
    "name": "click-loglevel",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "cli option,click,command line interface,log level,log option,logging,option parsing",
    "author": "John Thorvald Wodder II",
    "author_email": "click-loglevel@varonathe.org",
    "download_url": "https://files.pythonhosted.org/packages/56/61/46b588b807c5b7fc3904ff5d68a7f24b62166b9fd9c8b943462d92eb1649/click-loglevel-0.5.0.tar.gz",
    "platform": null,
    "description": ".. image:: http://www.repostatus.org/badges/latest/active.svg\n    :target: http://www.repostatus.org/#active\n    :alt: Project Status: Active \u2014 The project has reached a stable, usable\n          state and is being actively developed.\n\n.. image:: https://github.com/jwodder/click-loglevel/workflows/Test/badge.svg?branch=master\n    :target: https://github.com/jwodder/click-loglevel/actions?workflow=Test\n    :alt: CI Status\n\n.. image:: https://codecov.io/gh/jwodder/click-loglevel/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/jwodder/click-loglevel\n\n.. image:: https://img.shields.io/pypi/pyversions/click-loglevel.svg\n    :target: https://pypi.org/project/click-loglevel/\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/click-loglevel.svg\n    :target: https://anaconda.org/conda-forge/click-loglevel\n    :alt: Conda Version\n\n.. image:: https://img.shields.io/github/license/jwodder/click-loglevel.svg\n    :target: https://opensource.org/licenses/MIT\n    :alt: MIT License\n\n`GitHub <https://github.com/jwodder/click-loglevel>`_\n| `PyPI <https://pypi.org/project/click-loglevel/>`_\n| `Issues <https://github.com/jwodder/click-loglevel/issues>`_\n| `Changelog <https://github.com/jwodder/click-loglevel/blob/master/CHANGELOG.md>`_\n\n``click-loglevel`` provides a ``LogLevel`` parameter type for use in Click_\nprograms that wish to let the user set the logging level.  It accepts all of\nthe ``logging`` log level names (``CRITICAL``, ``ERROR``, ``WARNING``,\n``INFO``, ``DEBUG``, and ``NOTSET``, all case insensitive), and converts them\ninto their corresponding numeric values.  It also accepts integer values and\nleaves them as-is.  Custom log levels are also supported.\n\nStarting in version 0.4.0, shell completion of log level names (both built-in\nand custom) is also supported.\n\n.. _Click: https://palletsprojects.com/p/click/\n\n\nInstallation\n============\n``click-loglevel`` requires Python 3.7 or higher.  Just use `pip\n<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install it::\n\n    python3 -m pip install click-loglevel\n\n\nExamples\n========\n\n``myscript.py``:\n\n.. code:: python\n\n    import logging\n    import click\n    from click_loglevel import LogLevel\n\n\n    @click.command()\n    @click.option(\n        \"-l\",\n        \"--log-level\",\n        type=LogLevel(),\n        default=\"INFO\",\n        help=\"Set logging level\",\n        show_default=True,\n    )\n    def main(log_level: int) -> None:\n        logging.basicConfig(\n            format=\"[%(levelname)-8s] %(message)s\",\n            level=log_level,\n        )\n        logging.log(log_level, \"Log level set to %r\", log_level)\n\n\n    if __name__ == \"__main__\":\n        main()\n\nRunning ``myscript.py``:\n\n.. code:: console\n\n    $ python3 myscript.py\n    [INFO    ] Log level set to 20\n    $ python3 myscript.py --log-level DEBUG\n    [DEBUG   ] Log level set to 10\n    $ python3 myscript.py --log-level error\n    [ERROR   ] Log level set to 40\n    $ python3 myscript.py --log-level 15\n    [Level 15] Log level set to 15\n\nScript with custom log levels:\n\n.. code:: python\n\n    import logging\n    import click\n    from click_loglevel import LogLevel\n\n\n    logging.addLevelName(15, \"VERBOSE\")\n    logging.addLevelName(25, \"NOTICE\")\n\n\n    @click.command()\n    @click.option(\n        \"-l\",\n        \"--log-level\",\n        type=LogLevel(extra=[\"VERBOSE\", \"NOTICE\"]),\n        default=\"INFO\",\n        help=\"Set logging level\",\n        show_default=True,\n    )\n    def main(log_level: int) -> None:\n        logging.basicConfig(\n            format=\"[%(levelname)-8s] %(message)s\",\n            level=log_level,\n        )\n        logging.log(log_level, \"Log level set to %r\", log_level)\n\n\n    if __name__ == \"__main__\":\n        main()\n\n\nAPI\n===\n\nThe ``click_loglevel`` module contains a single class:\n\n``LogLevel``\n------------\n\nA subclass of ``click.ParamType`` that accepts the standard logging level names\n(case insensitive) and converts them to their corresponding numeric values.  It\nalso accepts integer values and leaves them as-is.\n\nCustom log levels can be added by passing them as the ``extra`` argument to the\nconstructor.  ``extra`` can be either an iterable of level names (in which case\nthe levels must have already been defined \u2014 typically at the module level \u2014 by\ncalling ``logging.addLevelName()``) or a mapping from level names to their\ncorresponding values.  All custom log levels will be recognized case\ninsensitively; if two different level names differ only in case, the result is\nundefined.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Log level parameter type for Click",
    "version": "0.5.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/jwodder/click-loglevel/issues",
        "Homepage": "https://github.com/jwodder/click-loglevel",
        "Source Code": "https://github.com/jwodder/click-loglevel"
    },
    "split_keywords": [
        "cli option",
        "click",
        "command line interface",
        "log level",
        "log option",
        "logging",
        "option parsing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7e37ba761b403fc58d2864da95403664b8b0485c3871f74eb932561e5a7a4fe",
                "md5": "bc565ba92eda67b37e1b89e83d7517ee",
                "sha256": "897070fd4bf5b503edb5a1ecc0551448647901f4fac83a01c9f00aa28ad86d60"
            },
            "downloads": -1,
            "filename": "click_loglevel-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bc565ba92eda67b37e1b89e83d7517ee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5534,
            "upload_time": "2023-10-09T18:15:02",
            "upload_time_iso_8601": "2023-10-09T18:15:02.183252Z",
            "url": "https://files.pythonhosted.org/packages/f7/e3/7ba761b403fc58d2864da95403664b8b0485c3871f74eb932561e5a7a4fe/click_loglevel-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "566146b588b807c5b7fc3904ff5d68a7f24b62166b9fd9c8b943462d92eb1649",
                "md5": "fc40e392149e1373b31f64ecc81ce484",
                "sha256": "fcc98a136a96479b4768494df25017114ba1cb525dac0bed619209b3578fd4f3"
            },
            "downloads": -1,
            "filename": "click-loglevel-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fc40e392149e1373b31f64ecc81ce484",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7597,
            "upload_time": "2023-10-09T18:15:04",
            "upload_time_iso_8601": "2023-10-09T18:15:04.291465Z",
            "url": "https://files.pythonhosted.org/packages/56/61/46b588b807c5b7fc3904ff5d68a7f24b62166b9fd9c8b943462d92eb1649/click-loglevel-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-09 18:15:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jwodder",
    "github_project": "click-loglevel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "click-loglevel"
}
        
Elapsed time: 0.33502s