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.
pip install click-logVerified import paths — ran on the pinned version, not inferred.
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.
Place `@simple_verbosity_option(logger)` directly under `@click.command()` or `@click.group()`.
Ensure `click_log.basic_config(logger)` is called before your CLI command executes or manually add a `StreamHandler` to your logger.
Verify your `pip install` command is `pip install click-log` and your imports use `import click_log` or `from click_log import ...`.
Install the library using pip: `pip install click-log`
Replace `click_log.init()` with `click_log.basic_config(logger)` and apply `@click_log.simple_verbosity_option(logger)` as a decorator to your Click command or group.
Ensure `click_log.basic_config(logger)` is called once at the start of your application. When using `@click_log.simple_verbosity_option(logger)`, place it as the highest (closest to `@click.command()`) decorator to ensure logging setup occurs before other Click options are processed.