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 message configured Loggair — get_logger() alone starts nothing, so a library that only asks for its logger prints and writes nothing. 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.

Switches that exist only as environment variables: LOGGAIR_EAGER_ENQUEUE, LOGGAIR_DISABLE_LOGGING, LOGGAIR_DISABLE_MULTIPROCESS_LOGGING and NO_COLOR (see configuration). The file env.complete lists every variable, ready to copy into a .env.

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.3.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

PolyForm Noncommercial License 1.0.0 (the LICENSE file): free for personal, academic and other noncommercial use. Commercial use needs a separate licence from the author.

Metadata

Release files for loggair 0.3.0

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.3.0
File Size Uploaded Provenance Actions
loggair-0.3.0.tar.gz 117.3 kB With provenance Details for loggair-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 179.3 kB

Release files / loggair-0.3.0.tar.gz

Download URL loggair-0.3.0.tar.gz
Size 117.3 kB
Tags Source
SHA-256 checksum
How to use checksums
33749ccf363e786b5adabc7305072a59ae7a801bd46421ba1f66ecb380d76a4b
BLAKE2b-256 checksum
How to use checksums
8a967edd4e0150008105e4012b409a6214bea87cd9601a0de3499b39349b76dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

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

Download URL loggair-0.3.0-py3-none-any.whl
Size 62.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
229347d37100960780e648d045ace52d800c9b77e90ba0b47a9cc7dd536a878a
BLAKE2b-256 checksum
How to use checksums
4aa9b915eaaaef86c45592b49223287b1099296b8e903e744b5c5fbd9660e4f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for loggair 0.3.0

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.3.0.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 Nov 26, 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