Skip to main content

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
)

Setting the collector address directly

A component that knows the collector address itself (Hannah Core, which announces it) passes it in instead of subscribing to discovery:

shipping.set_collector_address("192.168.1.10:50061")   # None withdraws it

It starts shipping if connect hasn't been called yet, takes precedence over the static collector_address, and a new address moves the stream.

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 as hannah.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
  • Bearer tokens, 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 through shipping.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.
  • Instance name: tells several instances of a component apart in the export. Without instance, the library uses the HANNAH_LOG_INSTANCE environment variable, else the hostname. In a container whose hostname is just its ID (a new one with every recreate), it uses container instead. Running the same component in several containers? Set HANNAH_LOG_INSTANCE, or hostname: in Compose.
  • 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_address is used while none is announced.
  • Never blocks the component: sending runs on its own threads. Connection problems are logged once to the hannah_logging logger (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=…)).

Metadata

Release files for hannah-logging 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hannah-logging 0.3.1
File Size Uploaded Provenance Actions
hannah_logging-0.3.1.tar.gz 17.1 kB Without provenance Details for hannah_logging-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hannah-logging 0.3.1
File Interpreter ABI Platform Actions
hannah_logging-0.3.1-py3-none-any.whl Python 3 none any Details for hannah_logging-0.3.1-py3-none-any.whl

Total release size: 30.3 kB

Release files / hannah_logging-0.3.1.tar.gz

Download URL hannah_logging-0.3.1.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a96296143b4039698c74ac969716074f6f5b77e4dfbe718a5de66dcadf0c81ca
BLAKE2b-256 checksum
How to use checksums
78e3cd7f765033f7fbafacc67a002521c8f2b206b3a1d3601663fe7be0b72105
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.3.1-py3-none-any.whl

Download URL hannah_logging-0.3.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d1c8f871750233038afbddd3d8a8566fa9197fd0159eb31679f0f6a4dda3152
BLAKE2b-256 checksum
How to use checksums
a1d380035a1be5b23884f3055aa335ada6517e28b91732fd3bb732247ee3de31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.6

Security for hannah-logging 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page