Registry / observability / tiered-debug

tiered-debug

JSON →
library1.4.0pypypi✓ verified 86d ago

Tiered Debug is a Python logging helper module that provides multiple, configurable levels of debug logging. It wraps standard Python `logging.debug()` calls, allowing developers to set a maximum debug tier that will be logged at runtime. The library is actively maintained, with version 1.4.0 released recently, and shows a consistent release cadence with several updates in the past year.

pip install tiered-debug
INSTALL
IMPORT
SIG · TIERED-DEBUG
T
tiered-debug
observabilitypythonv1.4.0
Install
1.5s avg
Import
38ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.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.910 runs
installs and imports cleanly · install 0.0s · import 0.040s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.035s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

TieredDebug
from tiered_debug import TieredDebug

This quickstart demonstrates how to instantiate `TieredDebug`, set its debug level, and log messages using the `lvX()` methods or the generic `log()` method. It also shows how to temporarily adjust the logging level using the `log_level_context` context manager and how to pass standard `logging` keyword arguments like `exc_info`.

import logging import os from tiered_debug import TieredDebug # Configure a basic logger for demonstration logging.basicConfig( level=logging.DEBUG, format='%(levelname)s:%(name)s:%(message)s' ) # Instantiate TieredDebug with a specific level or rely on default (1) # The debug_level argument overrides any TIERED_DEBUG_LEVEL env var for this instance. td = TieredDebug(debug_level=3, logger_name="my_app") # Log at different tiers td.lv1("This is a level 1 debug message. Always visible if debug_level >= 1.") td.lv2("This is a level 2 debug message. Visible if debug_level >= 2.") td.lv3("This is a level 3 debug message. Visible if debug_level >= 3.") td.lv4("This is a level 4 debug message. Not visible with current config (debug_level=3).") # Using the generic log method td.log(5, "This message is also at level 5. Not visible.") # Temporarily increase the debug level using a context manager print("\n--- Entering higher debug context ---") with td.log_level_context(5): td.lv4("This level 4 message is now visible within the context!") td.lv5("And this level 5 message is also visible!") # You can also pass keyword arguments directly to the underlying logging call try: raise ValueError("Something went wrong!") except ValueError: td.lv1("Error with exc_info", exc_info=True) print("--- Exiting higher debug context ---") td.lv4("This level 4 message is no longer visible after exiting the context.")
Debug
Known issues
breakingVersion 1.1.0 introduced a class-based structure (`TieredDebug`) that replaced the primary reliance on global functions and the `TIERED_DEBUG_LEVEL` environment variable for controlling debug levels. Code written for 1.0.x will not work directly with 1.1.x+ without migrating to the `TieredDebug` class.
fix
Refactor code to instantiate `TieredDebug` and use its instance methods (`lv1`, `lv2`, `log`, `set_level`, etc.) instead of the old module-level functions. The `debug_level` argument in the constructor replaces the environment variable for instance-specific control.
affects: 1.0.x to 1.1.0+
gotchaThe default handling of `exc_info`, `stack_info`, `stacklevel`, and `extra` keyword arguments in `log`, `lv1` through `lv5` methods has been inconsistent across versions 1.3.0, 1.3.1, and 1.4.0. This can lead to subtle differences in how these parameters are passed to the underlying `logging` module, especially if `None` was explicitly provided or implied by omitting the argument.
fix
Always explicitly pass `False`, `True`, or an appropriate value for `exc_info`, `stack_info`, `stacklevel`, and `extra` if you require specific behavior, rather than relying on the method's default `None` (which defers to the `logging` module's default) or specific boolean defaults.
affects: 1.3.0, 1.3.1, 1.4.0
gotchaWhile `TieredDebug` helps manage debug levels, it still relies on the standard Python `logging` module for handlers, formatters, and actual output. If no `logging.Handler` is configured for the `TieredDebug` instance's logger, messages may not appear even if the debug level is met.
fix
Ensure that the `logging` module is properly configured with at least one handler (e.g., `logging.basicConfig()` or `td.add_handler(logging.StreamHandler())`) and that the logger's level is set to `logging.DEBUG` or lower to capture debug messages.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'debug'
The Python package is named `tiered-debug` on PyPI, but its internal module name is `tiered_debug` (with an underscore) when imported.
fix
Change your import statement from `import debug` or `from debug import ...` to `from tiered_debug import TieredDebug`.
Logging messages are not appearing, even when the debug level is set correctly.
The underlying `logging` module's handlers or logger level are not configured to process `DEBUG` level messages. `TieredDebug` controls *which* debug level messages are sent, but `logging` controls *if* they are handled.
fix
Before instantiating `TieredDebug` or using its methods, ensure `logging.basicConfig(level=logging.DEBUG)` is called, or explicitly add a handler to the `TieredDebug` instance's logger using `td.add_handler(my_handler)` and set the logger's level to `logging.DEBUG`.
Environment variable TIERED_DEBUG_LEVEL is set, but my TieredDebug instance isn't respecting it.
Since version 1.1.0, the `TieredDebug` class constructor's `debug_level` argument takes precedence over the `TIERED_DEBUG_LEVEL` environment variable. If `debug_level` is explicitly passed, the environment variable is ignored for that instance.
fix
To have an instance respect the environment variable, initialize it without the `debug_level` argument: `td = TieredDebug()`. Alternatively, explicitly set the `debug_level` in the constructor: `td = TieredDebug(debug_level=int(os.getenv('TIERED_DEBUG_LEVEL', '1')))`.
Upgrade
Version history
1.4.0latest on PyPI · released Oct 7, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
tiered-debug — pip install tiered-debug · libregistry