{"id":2434,"library":"click-log","title":"Logging integration for Click","description":"click-log provides a simple and beautiful logging integration for Click applications, offering sensible defaults such as colorized output and an easy-to-use verbosity option. It simplifies the setup of Python's standard `logging` module within a Click CLI. The current version is 0.4.0, with an irregular release cadence, last updated in March 2022.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/click-contrib/click-log","tags":["click","logging","cli","command-line-interface"],"install":[{"cmd":"pip install click-log","lang":"bash","label":"Install click-log"}],"dependencies":[{"reason":"Core dependency for CLI application building.","package":"click","optional":false}],"imports":[{"symbol":"basic_config","correct":"from click_log import basic_config"},{"symbol":"simple_verbosity_option","correct":"from click_log import simple_verbosity_option"},{"note":"While `ClickHandler` is in `click_log.core`, it's typically exposed directly via `click_log` for simpler import paths and can be used to customize handlers.","wrong":"from click_log.core import ClickHandler","symbol":"ClickHandler","correct":"from click_log import ClickHandler"}],"quickstart":{"code":"import logging\nimport click\nfrom click_log import basic_config, simple_verbosity_option\n\nlogger = logging.getLogger(__name__)\nbasic_config(logger)\n\n@click.command()\n@simple_verbosity_option(logger)\ndef cli():\n    logger.info(\"This is an info message.\")\n    logger.warning(\"This is a warning message.\")\n    try:\n        1 / 0\n    except ZeroDivisionError:\n        logger.error(\"Caught a division by zero error!\")\n\nif __name__ == '__main__':\n    cli()","lang":"python","description":"This example demonstrates how to integrate `click-log` into a Click CLI. It initializes a logger, configures basic logging with `click-log.basic_config()`, and adds a `--verbosity` option using `simple_verbosity_option()` to control log levels. Running `python your_script.py --verbosity debug` will show all messages, while omitting the option or setting `info` will show info, warning, and error messages."},"warnings":[{"fix":"Place `@simple_verbosity_option(logger)` directly under `@click.command()` or `@click.group()`.","message":"The `simple_verbosity_option()` decorator should be applied as early as possible in the decorator stack (i.e., immediately below `@click.command()` or `@click.group()`). Defining it too late might result in logging not being configured early enough for other eager Click options or parameters.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `click_log.basic_config(logger)` is called before your CLI command executes or manually add a `StreamHandler` to your logger.","message":"Failing to call `click_log.basic_config(logger)` or manually attach a `logging.Handler` to your logger instance will prevent log messages from being displayed, even if `logger.info()` or `logger.error()` are called. `click-log`'s main purpose is to simplify this setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify your `pip install` command is `pip install click-log` and your imports use `import click_log` or `from click_log import ...`.","message":"Be careful not to confuse `click-log` (the correct package without a hyphen) with `click-logging` (an older, potentially unrelated project with a hyphen in the name on PyPI). Ensure you install and import from `click_log`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}