f_log
F Log is a simple, fast, and efficient Rust logger
Features
- Logging with background flush
- Configurable logger parameters for latency and throughput
- Convenient logging macros (
trace!,debug!,info!,warn!,error!) - Uses
compact_strfor efficient string storage - Customizable logger configuration through
LoggerConfig - Automatically flushes logs on panic
Getting Started
Add f_log to your Cargo.toml dependencies:
[]
= { = "0.1", = ["global"] }
Basic Usage
Initialize the logger with your preferred configuration and use the logging macros as shown below:
use Instant;
use ;
Logger Configuration
You can configure f_log using the LoggerConfig struct:
LoggerConfig::default()– Balanced defaultsLoggerConfig::low_latency()– Prioritizes low latency with smaller buffers and frequent flushesLoggerConfig::high_throughput()– Prioritizes throughput with larger buffers and batching
Example:
use ;
Logging Scope: Global vs Local
f_log supports two logging scopes:
- Global logger — Shared across all threads and modules. Activate it with "global" feature
- Local logger — Thread-local logger, independent for each thread. Activate it with "local" feature
Each log macro takes a selector as its first argument:
-
g for global logger (batched and flushed automatically)
-
gf for global logger and force flush all the current global logs
-
l for local (thread-local) logger (batched and flushed automatically)
-
lf for local (thread-local) logger and force flush all the current local logs
Choose based on your use case. Here are examples using threads.
Example: Global Logger with Threads
use thread;
use ;
Example: Local Logger with Threads
use thread;
use ;
License
Licensed under MIT OR Apache-2.0