Logging driver for reovim.
This driver implements the kernel's Logger trait using the tracing ecosystem.
It bridges kernel pr_*! macros to tracing subscribers.
Architecture
Following Linux kernel design (mechanism vs policy):
- Kernel provides mechanism:
Loggertrait,Level,Record,pr_*!macros - This driver provides policy: Where logs go, formatting, filtering
┌─────────────────────────────────────────────────────────────────┐
│ User Code │
│ pr_info!("buffer {} opened", id); │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Kernel (printk/) │
│ Level │ Record │ Logger trait │ Global OnceLock │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Driver (drivers/log/) │
│ TracingLogger │ LogConfig │ init_logging() │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ tracing ecosystem │
│ tracing │ tracing-subscriber │ tracing-appender │
└─────────────────────────────────────────────────────────────────┘
Usage
use ;
use set_logger;
// Step 1: Initialize tracing subscriber
let config = default;
init_logging?;
// Step 2: Set TracingLogger as global kernel logger
static LOGGER: TracingLogger = TracingLogger;
set_logger?;
// Step 3: Now pr_*! macros route to tracing
pr_info!;
pr_debug!;
Environment Variable
Set REOVIM_LOG to control log level (overrides LogConfig.level):
REOVIM_LOG=debug
REOVIM_LOG=trace
REOVIM_LOG=reovim_kernel=trace,warn
Output Formats
- Plain:
2024-01-15T10:30:00Z INFO file.rs:42 message - JSON:
{"timestamp":"...","level":"INFO","target":"...","message":"..."} - Pretty: Colorized output for terminal (development)
File Rotation
When using LogOutput::File, log files can be rotated:
RotationPolicy::Never- Single fileRotationPolicy::Daily- Rotate at midnight UTCRotationPolicy::Hourly- Rotate every hour