Skip to main content

InstruktAI Python Logger

Centralized logging utilities for Python services.

This repo provides a shared, consistent logging contract (env vars + output format + log location) intended to keep logs highly queryable (including by AIs that only read a tail window).

Background and rationale live in docs/design.md. Publishing notes live in docs/publishing.md.

Install (editable, local workspace)

From PyPI (recommended):

pip install instruktai-python-logger

From GitHub:

pip install git+ssh://git@github.com/InstruktAI/python-logger.git

For a local checkout, make install prepares dependencies and development tooling only. Run make install-runtime separately when this user's rotation scheduler should be wired.

API

  • Python entrypoint: instrukt_ai_logging.configure_logging(...)
  • Logger helper: instrukt_ai_logging.get_logger(name) (named **kv logging)
  • CLI entrypoint: instrukt-ai-logs (reads recent log lines)

Example:

import logging
from instrukt_ai_logging import configure_logging

configure_logging("teleclaude")
logger = logging.getLogger("teleclaude.core")
logger.info("job_started", job_id="abc123", user_id=123)

Per-process log files (multi-producer apps)

When several processes belong to the same app (a daemon plus a watcher plus a cron, for example), each one can own its own file under the same app directory by passing source=:

configure_logging("teleclaude")                       # → teleclaude.log (default)
configure_logging("teleclaude", source="docs-watch")  # → docs-watch.log
configure_logging("teleclaude", source="cron")        # → cron.log

The .log extension is always appended; pass the bare stem. Files all live under $XDG_STATE_HOME/instrukt-ai/{app}/ (fallback ~/.local/state). The CLI merges them transparently (see below).

Environment variables (contract)

Per-app prefix model (example uses TELECLAUDE_):

  • TELECLAUDE_LOG_LEVEL
  • TELECLAUDE_THIRD_PARTY_LOG_LEVEL
  • TELECLAUDE_THIRD_PARTY_LOGGERS (comma-separated logger prefixes to spotlight, e.g. httpcore,telegram)
  • TELECLAUDE_MUTED_LOGGERS (comma-separated logger prefixes to force to WARNING+, e.g. teleclaude.cli.tui)

These four per-app variables are the entire contract. There is no log-root override variable — the location is a fixed rule (see below).

Log location (contract)

Every app's logs live at the same predictable, prose-citable location on both macOS and Linux:

  • $XDG_STATE_HOME/instrukt-ai/{app}/{app}.log (fallback ~/.local/state, per the XDG Base Directory spec)

This path is always user-writable — no installer step, no sudo, no elevated permissions. configure_logging(...) raises immediately if the log file cannot be opened; logging is an essential subsystem and a process that cannot write its logs must not start blind.

Rotation

Rotation runs entirely in user space. At deploy, run instrukt-ai-log-setup once (or make install-runtime in this repository) to wire the per-user rotation conf plus scheduler: a launchd LaunchAgent on macOS running newsyslog, or a systemd user timer on Linux running logrotate. Re-running setup on an already-wired machine reports healthy.

configure_logging(...) only creates and opens the log file; it never writes rotation assets or invokes launchd/systemd. No /etc configuration, no sudo, and no system rotation daemon ever touches these files, so rotated/recreated logs always stay owned by the producing user.

CLI

# Last 10 minutes (default), follows
instrukt-ai-logs teleclaude -f

# Last 2 hours
instrukt-ai-logs teleclaude --since 2h

# Filter with regex
instrukt-ai-logs teleclaude --since 10m --grep 'logger=teleclaude'

# Follow (tail -f style) after printing the --since window
instrukt-ai-logs teleclaude --since 10m --follow

# Restrict to specific source streams (per-process files)
instrukt-ai-logs teleclaude --since 1h --logs=cron,docs-watch

Without --logs, every *.log* file in the app directory is merged by timestamp (rotation suffixes included). With --logs=stem1,stem2, only files whose stem matches an entry are read — exact stem match, so --logs=cron picks cron.log, cron.log.0, cron.log.1 and never cron-backup.log. Follow mode reads each selected file with one polling thread per file.

Metadata

Release files for instruktai-python-logger 0.6.7

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

Source distribution (sdist)

Source distribution for instruktai-python-logger 0.6.7
File Size Uploaded Provenance Actions
instruktai_python_logger-0.6.7.tar.gz 26.6 kB Without provenance Details for instruktai_python_logger-0.6.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for instruktai-python-logger 0.6.7
File Interpreter ABI Platform Actions
instruktai_python_logger-0.6.7-py3-none-any.whl Python 3 none any Details for instruktai_python_logger-0.6.7-py3-none-any.whl

Total release size: 45.2 kB

Release files / instruktai_python_logger-0.6.7.tar.gz

Download URL instruktai_python_logger-0.6.7.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0baa3f882e32c99da753ec8c2b4e4d2151f20eac9e33725f8da89bbe46e6d29e
BLAKE2b-256 checksum
How to use checksums
d129dcba997577464c67c9e16a669d1aed360c6b3172685317a75615c5d6e35c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / instruktai_python_logger-0.6.7-py3-none-any.whl

Download URL instruktai_python_logger-0.6.7-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34d563de5071a4130ca9cc4337ed4a617707bf1c21f640ed02df30bf17f153fc
BLAKE2b-256 checksum
How to use checksums
5f3705993af519b3d9e697d54740b045925bcc6d796edfea2eab2d22240d9e2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for instruktai-python-logger 0.6.7

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.

Release history Release notifications | RSS feed

This release

0.6.7 This release

2 release files No provenance

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