Master Log Rust Client
Rust client for sending structured logs to Master Log. It mirrors the Python client’s core shape: environment configuration, a configure() function that takes precedence over env values, simple module-level logging helpers, explicit client instances, automatic host/process metadata, TTL support, background batching, flush/shutdown, backpressure, and a minimum HTTP request interval.
Environment
Linux/macOS:
Windows PowerShell:
$env:MASTER_LOG_API_KEY = "dev-key"
$env:MASTER_LOG_ENDPOINT = "http://127.0.0.1:8000"
MASTER_LOG_ENDPOINT may be the backend root, /api/v1, /api/v1/logs, or /api/v1/logs/batch.
Optional controls:
Add To A Rust Project
From a local checkout:
[]
= { = "../master_log_clients/rust" }
= "1"
Simple Usage
use Duration;
use ;
Configure In Code
Values passed to configure() are used immediately and take precedence over MASTER_LOG_API_KEY and MASTER_LOG_ENDPOINT.
use Duration;
use ;
Structured Fields
use Duration;
use ;
use json;
Explicit Client
use Duration;
use ;
Background Batching
The Rust client defaults to a background worker thread. Calls enqueue log events locally and wake the worker. The worker drains the queue, batches events, and sends them to /api/v1/logs/batch.
min_request_interval or MASTER_LOG_MIN_REQUEST_INTERVAL_SECONDS enforces a minimum delay between actual HTTP request starts. This is separate from flush_interval: a full batch can wake the worker immediately, but the worker still waits until the minimum request interval has elapsed.
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. Use backpressure(false) only when the caller already has its own rate limit.
Use async_mode(false) when a program must block on every send or when a background thread is not appropriate.
Automatic Metadata
Every event includes a rust_client metadata block with:
- Hostname
- Process id
- Process name
argv0- Current working directory
- Library name and version
Failures are non-fatal by default. Logging calls return MasterLogResult with ok, status_code, event_id, queued, accepted, response, and error. Use try_log() or try_log_entry() on MasterLogClient when Rust Result errors are preferred.