loxide
A fast, dependency-free structured logging library for Rust.
loxide is a small, batteries-included logger for applications and services. It produces colored, human-readable logs in development and compact JSON in production — automatically — with scoped context, sensitive-field redaction, and ergonomic macros. It has zero third-party dependencies: its JSON value type and UTC time formatting are built entirely on the standard library, so it compiles quickly and adds nothing to your dependency tree.
Table of contents
- Why loxide?
- Installation
- Quick start
- Output formats
- Log levels
- Structured fields
- Sub-loggers (scoped context)
- Automatic redaction
- Convenience helpers
- Configuration
- Writing to a custom sink
- Performance & thread-safety
- MSRV
- License
Why loxide?
- Zero dependencies. No
serde, nochrono— nothing. Faster builds, smaller supply chain, fewer CVEs to track. - Two formats, one API. Pretty for humans, JSON for machines.
Format::Autopicks the right one based on whether stderr is a terminal. - Structured by default. Every record carries typed key/value fields.
- Safe by default. Secrets such as
passwordandapi_keyare redacted in both formats, so they never leak into your logs. - Ergonomic.
log_info!(logger, "msg", "k" => v)macros capture the call site automatically; sub-loggers attach context once. - Thread-safe & cheap to clone. Share one logger across your whole app.
Installation
[]
= "0.0.5"
Or from the command line:
Quick start
use ;
Output formats
Format::Auto (the default) renders pretty output when stderr is a terminal
and JSON otherwise:
Pretty
2026/07/12 10:11:12 UTC INF server started port=8080 tls=true
JSON
Force a format explicitly with Config::default().with_format(Format::Json).
Log levels
From least to most severe: Trace, Debug, Info, Warn, Error, Fatal.
A record is emitted only when its level is at least the configured minimum, so
setting the logger to Warn silently drops Info and below.
use ;
let logger = new;
logger.info; // dropped
logger.error; // emitted
Each level has a shortcut method (logger.info(...)) and a call-site-capturing
macro (log_info!, log_warn!, …).
Structured fields
Field values accept anything convertible into a JsonValue (strings, integers,
floats, bools, Option, Vec, …) via the json! macro:
use ;
let logger = new;
log_info!;
An error field is highlighted in red in pretty output.
Sub-loggers (scoped context)
Attach context once; it appears on every record the sub-logger emits. Sub-loggers share the parent's output sink, so they are cheap to create.
use ;
let logger = new;
let request = logger.with_component.with_request_id;
request.info;
// => ... component=api request_id=req-7 path=/health
with_component, with_request_id, and with_trace_id are shorthands for the
general with_field(key, value).
Automatic redaction
Fields whose key looks sensitive are masked automatically — in both pretty and JSON output:
use ;
let logger = new;
logger.info;
// password is rendered as "s**************s", never in the clear
Detected substrings include password, secret, token, authorization,
api_key, private_key, credential, credit_card, cvv, ssn, and more.
You can also scrub a map yourself with redact_map, or check a key with
is_sensitive_key.
Convenience helpers
The helpers module provides ready-made loggers for recurring events, with
consistent field names and levels:
use ;
let logger = new;
log_request;
log_response; // level from status
log_db_query;
log_response chooses the level from the status code (5xx → error, 4xx →
warn, else info). See also log_service_error, log_service_debug, and the
log_success! macro (or Logger::success) for positive milestones.
Configuration
Build a Config directly, tweak it with the with_* builder methods, or read
the environment:
use ;
let logger = new;
| Variable | Effect |
|---|---|
LOG_LEVEL |
Minimum level (trace..fatal; aliases accepted). |
LOG_FORMAT |
auto, pretty, or json. |
LOG_CALLER |
1 or true enables file:line in records. |
NO_COLOR |
If set (any value), disables ANSI colors. |
TERM |
dumb disables colors. |
Writing to a custom sink
Any Box<dyn Write + Send> works — files, buffers, sockets:
use ;
let file = create.unwrap;
let logger = with_writer;
logger.info;
Logger::new writes to stderr and Logger::stdout writes to stdout.
Performance & thread-safety
Logger is Clone and Send + Sync. The output sink is shared behind an
Arc<Mutex<…>>, and each record is rendered to a single string and written with
one locked writeln!, so concurrent records never interleave. Sharing one logger
(and its sub-loggers) across threads is the intended usage.
Use logger.enabled(level) to guard expensive field computation:
# use ;
# let logger = new;
if logger.enabled
MSRV
loxide requires Rust 1.88 or newer (edition 2024).
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.