Dependency-free Python client for Master Log
Project description
Master Log Python Client
Small dependency-free Python client for sending logs to Master Log.
Environment
export MASTER_LOG_API_KEY=dev-key
export MASTER_LOG_ENDPOINT=http://127.0.0.1:8000
MASTER_LOG_ENDPOINT may be the backend root, /api/v1, or /api/v1/logs.
Optional controls:
export MASTER_LOG_BATCH_SIZE=100
export MASTER_LOG_FLUSH_INTERVAL_SECONDS=1.0
export MASTER_LOG_MAX_QUEUE_SIZE=10000
export MASTER_LOG_DROP_WHEN_FULL=true
export MASTER_LOG_QUEUE_TIMEOUT_SECONDS=0.25
export MASTER_LOG_BACKPRESSURE=true
export MASTER_LOG_INITIAL_SEND_SECONDS_PER_LOG=0.005
export MASTER_LOG_MAX_ENQUEUE_SLEEP_SECONDS=0.25
export MASTER_LOG_MIN_REQUEST_INTERVAL_SECONDS=0.25
Install For Local Use
From this directory:
python -m pip install -e .
Simple Usage
from master_log_client import flush, mlog
mlog("Telescope array online")
mlog("Dome slit wind threshold approaching", severity="warn", tags=["dome", "weather"])
flush()
Configure In Code
Use configure() when you do not want to rely on environment variables. Values passed to
configure() take precedence over MASTER_LOG_API_KEY and MASTER_LOG_ENDPOINT.
from master_log_client import configure, flush, mlog
configure(
api_key="dev-key",
endpoint="http://127.0.0.1:8000",
batch_size=100,
flush_interval_seconds=1.0,
)
mlog("Telescope array online", tags=["observatory", "telescope"])
flush()
Background Batching
By default, the client starts a small multiprocessing worker on platforms with fork support when no custom transport is configured. Calls to mlog() enqueue events locally and wake the worker. The worker drains the queue, batches events, and sends them to /api/v1/logs/batch.
Use min_request_interval_seconds or MASTER_LOG_MIN_REQUEST_INTERVAL_SECONDS to enforce a minimum delay between actual HTTP request starts. This is separate from flush_interval_seconds: a full batch can wake the worker immediately, but the worker still waits until the minimum request interval has elapsed before sending the next request. The default is 0.0, which disables this hard request-rate limit.
Async enqueue is intentionally not free by default. After each queued log, the caller sleeps for the worker's moving average send time per accepted log. The first burst uses initial_send_seconds_per_log, then successful batch sends tune the value. This keeps accidental hot loops closer to the service's observed ingest rate instead of letting them fill the local queue immediately. Use backpressure=False or MASTER_LOG_BACKPRESSURE=false only when the caller already has its own rate limit.
Short scripts should call flush() before exiting when they need confirmation that queued logs were sent. The default client also flushes during interpreter shutdown on a best-effort basis.
from master_log_client import configure, flush, mlog, shutdown
configure(
api_key="dev-key",
endpoint="http://127.0.0.1:8000",
min_request_interval_seconds=0.25,
)
mlog("Mirror cover opened", tags=["startup", "telescope"])
mlog("Mount tracking enabled", tags=["mount"])
result = flush(timeout_seconds=5)
if not result.ok:
print("Master Log flush failed:", result.error)
shutdown()
Use async_mode=False when a script must block on every send, when testing with a custom transport, or when multiprocessing is not appropriate for the host process.
On platforms without fork support, such as Windows, the client defaults to synchronous sends. You can force async_mode=True or MASTER_LOG_ASYNC=true from a multiprocessing-safe application entrypoint.
from master_log_client import MasterLogClient
client = MasterLogClient(
api_key="dev-key",
endpoint="http://127.0.0.1:8000",
async_mode=False,
)
result = client.info("Synchronous log send", tags=["debugging"])
Severity Helpers
from master_log_client import debug, error, fatal, info, warn
info("Flat-field calibration completed", tags=["calibration", "ccd"])
warn("Seeing degraded", tags=["seeing", "atmosphere"], metadata={"fwhm_arcseconds": 3.4})
error("CCD cooling loop failed to settle", tags=["ccd", "camera"])
fatal("Pier collision guard triggered", tags=["mount", "safety"])
Print-Like Behavior
mlog accepts multiple values like print and joins them with sep.
from master_log_client import mlog
frame_id = 42
target = "M31"
mlog("Captured frame", frame_id, "for", target, tags=["imaging"])
Optional Fields
from master_log_client import mlog
mlog(
"Short-lived satellite glint crossed the exposure path.",
title="Temporary satellite glint alert",
severity="info",
tags=["transient", "satellite-pass"],
ttl_seconds=120,
metadata={"target": "M13", "duration_seconds": 18},
)
Automatic Metadata
Every event includes a python_client metadata block with:
- Hostname
- Fully qualified domain name when available
- Process id
- Process name
- Current working directory
- Python version
- Library version
Failures are non-fatal by default. The call returns a MasterLogResult with ok, status_code, event_id, queued, accepted, and error.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file master_log_client-0.1.0.tar.gz.
File metadata
- Download URL: master_log_client-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3cf4e0db7af5895ae9a81ff87d1e775ad6f653d81b1fd3172f897b3c5acdd7b
|
|
| MD5 |
c20d33def89ac4aa94cfb13f054d9795
|
|
| BLAKE2b-256 |
e0c5a69cdbe530e32c037a4ed5b735ce281b544f42cf97c1012e90b0d8c58d82
|
File details
Details for the file master_log_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: master_log_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09e5fcd944b3665ae9b273b0e182823edff4518f2b26f22f4a49b87e60181752
|
|
| MD5 |
a67b2e2a862da1814376a1abf2f394e9
|
|
| BLAKE2b-256 |
fe4d3e1328c332a79d40b886766e9fa5b502798101ed2bb27375e281d9238c68
|