hannah-logging (Python)
Ships the logs of a Hannah component to the Hannah log collector, so a user can download one archive of all components' logs from the WebUI.
The library adds one logging.Handler. Your existing handlers (stdout, journald, syslog)
keep working unchanged.
Installation
pip install hannah-logging
The library relies on the hannah-proto version the component already uses, because
every call to Hannah Core has to carry the matching protocol version.
Usage
import logging
import hannah_logging
logging.basicConfig(level=logging.INFO)
# As early as possible: everything logged from here on is buffered.
shipping = hannah_logging.install(
"telegram",
version=__version__,
secrets=[config.bot_token], # masked wherever they appear
logger_categories={"hannah.stt": hannah_logging.TRANSCRIPT},
)
# Once the config is loaded:
shipping.connect(
hannah_address="localhost:50051", # discovery via Hannah Core
collector_address=None, # optional static fallback
)
Categories
Each line is tagged GENERAL, TRANSCRIPT (speech transcripts, user utterances) or
METADATA (room and device names, presence). Exports can leave out the last two, and
the WebUI does so by default.
- By logger name:
logger_categories={"hannah.stt": TRANSCRIPT}also covers child loggers such ashannah.stt.whisper. - Per call:
log.info("heard: %s", text, extra={hannah_logging.CATEGORY_ATTR: hannah_logging.TRANSCRIPT})
Secrets
Before a line leaves the process, the library masks:
- values of keys such as
password,token,api_key,secret,psk Bearertokens, JWTs, credentials in URLs (mqtt://user:pw@host), PEM private keys- Telegram bot tokens and well-known token prefixes (
glpat-,ghp_, …) - every value passed as
secrets=[…]or later throughshipping.add_secret(…)
Extra regexes go in secret_patterns=[…]. The component's own handlers still see the
unmasked line.
Behaviour
- Buffer: 4 MiB by default (
max_buffer_bytes). When it is full, the oldest lines are dropped and reported to the collector as a gap. While no collector is known, the buffer simply keeps running as a ring. - Timestamps are taken when a line is logged, not when it is sent.
- Discovery: subscribes to Hannah Core's infrastructure announcements and follows the
log collector when it moves. If Core is unreachable, the last known collector is kept.
The static
collector_addressis used while none is announced. - Never blocks the component: sending runs on its own threads. Connection problems
are logged once to the
hannah_logginglogger (not shipped) and retried with backoff. - Shutdown: at exit, the library tries for up to 2 seconds to send what is still
buffered (
shipping.close(timeout=…)).
Release files for hannah-logging 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hannah_logging-0.1.0.tar.gz | 14.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hannah_logging-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / hannah_logging-0.1.0.tar.gz
| Download URL | hannah_logging-0.1.0.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50e8d22ff1a8e79a3d00a26221c122beff01d09165d434d23ef77d10b6af09ce
|
|
BLAKE2b-256 checksum How to use checksums |
eafb246b6df285cea744ab4ef45402ce373d208c1d10afb5e188484c9c629be5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / hannah_logging-0.1.0-py3-none-any.whl
| Download URL | hannah_logging-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ddb1a0fc1c472ff2100291e87f74e65c25180b6bf331fb23e813cb3165898c2
|
|
BLAKE2b-256 checksum How to use checksums |
1ed7223e9f43f364420e57133ac96e73c241c6c902c2a4d083c4f9b7ebf02533
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|