fastlogging — Documentation
fastlogging is a high-performance, thread-safe structured logging library for Rust. It routes messages through an asynchronous background thread to one or more independent writers (console, file, network client/server, syslog, callback), keeping your hot path free of blocking I/O — each call is a cheap level check followed by a channel send.
Table of Contents
- doc/LEVELS.md — Log-level constants and helper functions
- doc/LOGGING.md —
Loggingstruct — primary API - doc/LOGGER.md —
Loggerstruct — per-thread/per-domain handles - doc/WRITERS.md — Writer configurations: console, file, callback, syslog
- doc/NETWORK.md — Network logging — client and server writers
- doc/CONFIG.md — Extended config and file-based configuration
- doc/ROOT.md — Process-wide root logger (
ROOT_LOGGER) - doc/EXAMPLES.md — Full, runnable code examples
The full guide (quick start, architecture, features, platform notes) lives in doc/README.md.
Quick Start
Add to Cargo.toml:
[]
= "0.8"
One-liner default logger
use ;
Explicit console logger
use ;
OpenTelemetry
Export logs to an OpenTelemetry Collector over OTLP/HTTP with
OpenTelemetryWriterConfig. The writer posts batches to
{endpoint}/v1/logs; the default endpoint is http://localhost:4318.
use ;
See the complete example in examples/otel.rs.
Architecture
Log calls never touch I/O on the caller's thread. Each call performs a level check (the hot path), and if it passes, the message is handed to a flume-backed channel. A single LoggingThread running in the background drains that channel and dispatches to each writer's own thread.
@startuml
participant "Your code" as code
participant "server_tx\n(flume channel)" as ch
participant "LoggingThread\n(background)" as lt
participant "ConsoleWriter\n(thread)" as cw
participant "FileWriter\n(thread)" as fw
participant "ClientWriter\n(thread)" as clw
participant "LoggingServer\n(thread)" as ls
participant "CallbackWriter\n(thread)" as cbw
participant "SyslogWriter\n(thread, unix)" as sw
code -> code : level check\n(hot path — single\ninteger compare,\nno lock)
code -> ch : push message
ch -> lt : deliver
lt -> cw : dispatch
lt -> fw : dispatch
lt -> clw : dispatch
lt -> ls : dispatch
lt -> cbw : dispatch
lt -> sw : dispatch
@enduml
Each writer runs in its own background thread and consumes messages from a bounded channel. The level check on the hot path is a single integer comparison with no locking.
Crate Features
| Feature | Default | Description |
|---|---|---|
config_json |
✔ | Save / load configuration as JSON |
config_yaml |
✔ | Save / load configuration as YAML |
config_xml |
✔ | Save / load configuration as XML |
Disable all three to get a dependency-light build:
= { = "0.8", = false }
Platform Notes
SyslogWriter/SyslogWriterConfigare available on Unix only (#[cfg(target_family = "unix")]). On Windows the equivalent iseventlog-backed and exposed under the same type names.
Language Bindings
The Rust core is wrapped for other languages in sibling crates/directories:
| Binding | Layer | Repository dir |
|---|---|---|
| C | raw extern "C" ABI (cbindgen header) |
cfastlogging |
| C++ (cxx) | type-safe cxx bridge |
cxxfastlogging |
| C++ (wrapper) | C++17 RAII over the C ABI | cppfastlogging |
| Go | cgo wrapper | gofastlogging |
| Python | PyO3/maturin | pyfastlogging |
| Java (JNI) | JNI bindings | jfastlogging-jni |
| Java (FFM) | Foreign Function & Memory API | jfastlogging-ffm |