Skip to main content

Loggair

Multiprocess-safe logging for machine-learning and HPC runs, built on Loguru.

One get_logger() call gives every process of a distributed job a working setup: the console shows rank 0 only, the file keeps every rank, each run starts a fresh log file, and standard-library logging from PyTorch, TensorFlow, JAX and friends lands in the same stream. Everything else is a setting — a YAML key, an environment variable, or a keyword argument.

Install

pip install loggair                     # depends on loguru and pyyaml only
pip install "loggair[alerts]"           # + Slack/Teams/email alerting via apprise

Python 3.12 or newer.

Quick start

# train.py
from loggair import get_logger

logger = get_logger(__name__)

logger.info("Starting training loop...")
logger.debug("batch_size=32 lr=0.001")
logger.success("Model checkpoint saved!")

The console (stderr) shows INFO and above:

2026-10-13 12:16:29 | INFO     | loggair.core:configure_logging:942 | Loggair initialized: train.log
2026-10-13 12:16:29 | INFO     | __main__:<module>:5 | Starting training loop...
2026-10-13 12:16:29 | SUCCESS  | __main__:<module>:7 | Model checkpoint saved!

./logs/train.log keeps DEBUG and above, with millisecond timestamps:

2026-10-13 12:16:29.221 | INFO     | loggair.core:configure_logging:942 | Loggair initialized: train.log
2026-10-13 12:16:29.222 | INFO     | __main__:<module>:5 | Starting training loop...
2026-10-13 12:16:29.222 | DEBUG    | __main__:<module>:6 | batch_size=32 lr=0.001
2026-10-13 12:16:29.222 | SUCCESS  | __main__:<module>:7 | Model checkpoint saved!

What happened without any configuration:

  • The first get_logger() configured Loggair. The log file is named after the running script and lives in ./logs.
  • A train.log left by an earlier run was archived as train.<timestamp>.log first; the last 5 archives are kept.
  • Standard-library logging and warnings were redirected into the same two sinks.
  • In a torchrun, SLURM or mpirun job the same script prints from rank 0 only; the file keeps every rank, tagged [rank N].

Levels are Loguru's — TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL — plus TRAIL for call tracing. get_logger(name) mirrors logging.getLogger(name): the name becomes the {name} field and takes part in per-logger level rules.

Configure

Settings resolve, highest priority first: keyword arguments to configure_logging(), LOGGAIR_* environment variables, a loggair.yaml in the working directory, [tool.loggair] in pyproject.toml, ~/.config/loggair/config.yaml, then the defaults. Use whichever front door fits:

from loggair import configure_logging

configure_logging(log_dir="./experiment_logs", console_level="DEBUG")   # before the first get_logger()
# loggair.yaml
log_dir: ./experiment_logs
console_level: DEBUG
retention: 10
export LOGGAIR_DIR=/var/log/myapp LOGGAIR_CONSOLE_LEVEL=ERROR

Every setting, its environment variable and its default are in the configuration reference; loggair.example.yaml is the annotated template.

Common tasks

I want to… Setting or call Read more
quiet a chatty library on one sink only module_levels: {"httpx": {file: WARNING}} per-logger levels
give every rank and DataLoader worker its own file worker_files: true per-worker files
bound the log of a job that never restarts rotation: "100 MB" (or daily, 00:00) runtime rotation
compress archived logs compression: gz rotation and retention
ship JSON lines to Elasticsearch, Loki or Datadog serialize: true structured logging
stamp epoch and step on every record loggair.set_context(epoch=3) experiment context
get Slack, Teams or email on ERROR alert_urls: ["slack://..."] with pip install "loggair[alerts]" alerting
raise a running job to DEBUG kill -USR2 <pid> after debug_signal: SIGUSR2, or loggair.reconfigure(console_level="DEBUG") runtime changes
embed next to uvicorn or gunicorn intercept: coexist, intercept_exclude: ["uvicorn"] interception modes
log when functions are entered and left, with arguments @track / @spy call tracing
switch logging off entirely LOGGAIR_DISABLE_LOGGING=1 disabling logging
see what a process would be configured with python -m loggair diagnostics

Distributed training

No if rank == 0: around log calls:

from loggair import get_logger

logger = get_logger(__name__)
logger.info("Initializing process group...")   # console: once, from rank 0; file: every rank

Ranks are read from RANK, SLURM_PROCID, the MPI launchers' own variables (OMPI_COMM_WORLD_RANK, PMI_RANK, PMIX_RANK, MV2_COMM_WORLD_RANK), or LOCAL_RANK with the node topology. enqueue: true routes a shared file through a multiprocessing queue that is allocated only when the first child process appears; worker_files: true gives each writer its own file instead. The operations guide covers both, with rotation, retention and alerting for long-lived jobs.

Call tracing

from loggair import spy

@spy
def train(model, epochs=2, lr=0.001): ...
TRAIL | myapp:train:21 | → train(model=<myapp.Model object at 0x10883dd00>, epochs=7, lr=0.001) [from myapp:main:76]
TRAIL | myapp:train:21 | ← train (0.0 ms)

Records are emitted at TRAIL, a level between TRACE and DEBUG, so nothing appears until a sink or a module_levels rule is set that low. Switched off, a decorated call costs about 0.08 µs. @track logs entry and exit without the arguments; both decorate whole classes. The tracing guide has the options, the costs, and how configured objects render as their configuration.

Diagnose

$ python -m loggair
loggair 0.2.0  (loguru 0.7.3, python 3.13.14)
process:  MainProcess (pid 29487)
rank:     none detected (single-process, or rank 0 by default)

config files (highest priority first):
  [not found] loggair.yaml
  ...
resolved settings (args omitted — env > files > defaults):
  log_dir: "/home/me/project/logs"
  ...

Read-only: it configures nothing, rotates nothing and creates no directory, so it is safe beside a live run. --json emits the report for scripts; inside torchrun or srun it shows each rank's detected value. Details in the configuration reference.

Documentation

Document What it answers
Configuration reference Every setting and where it can be set; per-logger levels, coloring, formats, runtime changes, introspection, the diagnostic
Operations guide Ranks and worker files, rotation and retention, JSON output, alerting, interception modes, experiment context, embedding and teardown
Call tracing @track and @spy, the TRAIL level, class decoration, inherited methods, parameter rendering, cost
loggair.example.yaml Every key with its default, its environment variable and a comment
Architecture decisions Why it is built this way: rotation ownership, computed sink floors, signal handling, the tracing descriptor
Rationale How Loggair compares with stdlib logging, Loguru alone and framework loggers
Changelog and roadmap What each release changed; what is planned
examples/ mp_demo.py (four spawned workers, one file) and track_demo.py (every tracing example)

License

MIT

Metadata

Release files for loggair 0.2.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 loggair 0.2.1
File Size Uploaded Provenance Actions
loggair-0.2.1.tar.gz 108.9 kB With provenance Details for loggair-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for loggair 0.2.1
File Interpreter ABI Platform Actions
loggair-0.2.1-py3-none-any.whl Python 3 none any Details for loggair-0.2.1-py3-none-any.whl

Total release size: 168.2 kB

Release files / loggair-0.2.1.tar.gz

Download URL loggair-0.2.1.tar.gz
Size 108.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7eded26df4150748e73355a0c6d7586383f0497d841e8845f568128564094f1d
BLAKE2b-256 checksum
How to use checksums
ce2a0863354c50eda50e0dc7bccf9bfd03511c07b288f42c50d1aae4567a5584
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / loggair-0.2.1-py3-none-any.whl

Download URL loggair-0.2.1-py3-none-any.whl
Size 59.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f882c2f1a68b0a710953587667c4ac3a2e0b830b5a7f1d50a4bdf0a05403a7c
BLAKE2b-256 checksum
How to use checksums
93fed2d3ac2ba4c7e41a185ffb522dd8715b4ce418a391ba50cfa806475c14e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for loggair 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for loggair-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

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