A unified Logger and ProgressBar util with zero dependencies.
Project description
LogBar
A unified logger, table renderer, and progress bar utility with zero runtime dependencies.
Features
- Shared singleton logger with per-level colorized output.
oncehelpers prevent duplicate log spam automatically.- Progress bars that stay at the bottom while your logs flow freely.
- Column-aware tabular printer with spans, width hints, and
fitsizing. - Zero dependencies; works anywhere Python runs.
Installation
pip install logbar
LogBar works out-of-the-box with CPython 3.8+ on Linux, macOS, and Windows terminals.
Quick Start
import time
from logbar import LogBar
log = LogBar.shared()
log.info("hello from logbar")
log.info.once("this line shows once")
log.info.once("this line shows once") # silently skipped
for _ in log.pb(range(5)):
time.sleep(0.2)
Sample output (colors omitted in plain-text view):
INFO hello from logbar
INFO this line shows once
INFO [###---------------] 20% (1/5)
Logging
The shared instance exposes the standard level helpers plus once variants:
log.debug("details...")
log.warn("disk space is low")
log.error("cannot connect to database")
log.critical.once("fuse blown, shutting down")
Typical mixed-level output (Note: Markdown cannot display ANSI colors):
DEBUG model version=v2.9.1
WARN disk space is low (5%)
ERROR cannot connect to database
CRIT fuse blown, shutting down
Progress Bars
Progress bars accept any iterable or integer total:
for item in log.pb(tasks):
process(item)
for _ in log.pb(500).title("Downloading"):
time.sleep(0.05)
Manual mode gives full control when you need to interleave logging and redraws:
pb = log.pb(jobs).title("Processing").manual()
for job in pb:
log.info(f"starting {job}")
pb.subtitle(f"in-flight: {job}").draw()
run(job)
log.info(f"finished {job}")
Progress bar snapshot (plain-text example):
INFO Processing [##########------------] 40% (8/20) in-flight: step-8
The bar always re-renders at the bottom, so log lines never overwrite your progress.
Columns (Table)
Use log.columns(...) to format aligned tables while logging data streams. Print the column header per context with cols.info.header() (or cols.warn.header(), etc.). Columns support spans and three width hints:
- character width:
"24" - percentage of the available log width:
"30%" - content-driven fit:
"fit"
cols = log.columns(
{"label": "tag", "width": "fit"},
{"label": "duration", "width": 8},
{"label": "message", "span": 2}
)
cols.info.header()
cols.info("startup", "1.2s", "ready", "subsystem online")
cols.info("alignment", "0.5s", "resizing", "fit width active")
Sample table output (plain-text):
INFO +----------+----------+-----------------------------+------------------------------+
INFO | tag | duration | message | message |
INFO +----------+----------+-----------------------------+------------------------------+
INFO | startup | 1.2s | ready | subsystem online |
INFO +----------+----------+-----------------------------+------------------------------+
INFO | alignment| 0.5s | resizing | fit width active |
INFO +----------+----------+-----------------------------+------------------------------+
Notice how the tag column expands precisely to the longest value thanks to width="fit".
You can update column definitions at runtime:
cols.update({
"message": {"width": "40%"},
"duration": {"label": "time"}
})
Replacing tqdm
The API mirrors common tqdm patterns while staying more Pythonic:
# tqdm
for n in tqdm.tqdm(range(1000)):
consume(n)
# logbar
for n in log.pb(range(1000)):
consume(n)
Manual update comparison:
# tqdm manual mode
with tqdm.tqdm(total=len(items)) as pb:
for item in items:
handle(item)
pb.update()
# logbar manual redraw
with log.pb(items).manual() as pb:
for item in pb:
handle(item)
pb.render()
Advanced Tips
- Combine columns and progress bars by logging summaries at key checkpoints.
- Use
log.warn.once(...)to keep noisy health checks readable. - For multi-line messages, pre-format text and pass it as a single string; LogBar keeps borders intact.
Pending Features
- Multiple active progress bars
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file logbar-0.0.7.tar.gz.
File metadata
- Download URL: logbar-0.0.7.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9008ecda2a4c02ec10cc94a134bb9aa958a538548c8a55100c60e648b6a3c98
|
|
| MD5 |
88850614b8cdf10f2b94451a37cf2be3
|
|
| BLAKE2b-256 |
bcbab3a0cd755c18e3568042dd9bd58594fca196117a7e6dd5a761df7dd57e95
|