Registry / observability / click-log

click-log

JSON →
library0.4.0pypypi✓ verified 25d ago

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-log
INSTALL
IMPORT
SIG · CLICK-LOG
C
click-log
observabilitypythonv0.4.0
Install
1.7s avg
Import
81ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.088s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.074s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

basic_config
from click_log import basic_config
simple_verbosity_option
from click_log import simple_verbosity_option
ClickHandler
from click_log import ClickHandler
from click_log.core import ClickHandler
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.

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.

import logging import click from click_log import basic_config, simple_verbosity_option logger = logging.getLogger(__name__) basic_config(logger) @click.command() @simple_verbosity_option(logger) def cli(): logger.info("This is an info message.") logger.warning("This is a warning message.") try: 1 / 0 except ZeroDivisionError: logger.error("Caught a division by zero error!") if __name__ == '__main__': cli()
Debug
Known issues
gotchaThe `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.
fix
Place `@simple_verbosity_option(logger)` directly under `@click.command()` or `@click.group()`.
affects: All versions
gotchaFailing 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.
fix
Ensure `click_log.basic_config(logger)` is called before your CLI command executes or manually add a `StreamHandler` to your logger.
affects: All versions
gotchaBe 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`.
fix
Verify your `pip install` command is `pip install click-log` and your imports use `import click_log` or `from click_log import ...`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'click_log'
The 'click-log' library has not been installed in your Python environment or is not accessible.
fix
Install the library using pip: `pip install click-log`
AttributeError: module 'click_log' has no attribute 'init'
The `init` method was part of an older API for `click-log` and has been removed or replaced in newer versions (like 0.4.0) by `basic_config` and `simple_verbosity_option`.
fix
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.
click-log not displaying messages / logging output not appearing
Logging messages may not appear because the `click-log` setup, particularly the `@click_log.simple_verbosity_option` decorator, is not applied early enough in your Click command's decorator stack, or there's a conflict with a pre-existing `logging.basicConfig()` call.
fix
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.
Upgrade
Version history
0.4.0latest on PyPI · released Mar 13, 2022
Audit
Dependencies
clickrequiredCore dependency for CLI application building.
Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
1
Resources
click-log — pip install click-log · libregistry