Log Level Configuration
January 17, 2026 · View on GitHub
Overview
Ferrite v0.2.2 introduces configurable log levels, allowing users to control the verbosity of log output. This addresses GitHub Issue #11.
Key Files
| File | Purpose |
|---|---|
src/config/settings.rs | LogLevel enum and log_level field in Settings |
src/main.rs | CLI flag parsing and logging initialization |
docs/cli.md | CLI documentation with --log-level usage |
Implementation Details
LogLevel Enum
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum LogLevel {
Debug, // Most verbose
Info, // Informational messages
#[default]
Warn, // Warnings and errors (default)
Error, // Errors only
Off, // Disable logging
}
Helper Methods
display_name()- Human-readable name for UI/loggingdescription()- Detailed description for tooltipsall()- List of all available levelsto_level_filter()- Convert tolog::LevelFilterfor env_logger
Configuration Precedence
Log level is determined in this order (highest priority first):
- CLI flag -
ferrite --log-level debug - Config file -
"log_level": "debug"in config.json - Built-in default -
warn
Initialization Flow
// 1. Parse CLI arguments
let cli = Cli::parse();
// 2. Load config (includes log_level)
let settings = load_config();
// 3. Determine effective log level
let effective_log_level = cli.log_level.unwrap_or(settings.log_level);
// 4. Initialize logging
env_logger::Builder::new()
.filter_level(effective_log_level.to_level_filter())
.init();
Usage
CLI Override
# Enable debug logging
ferrite --log-level debug
# Show only errors
ferrite --log-level error
# Disable all logging
ferrite --log-level off
# Combine with file arguments
ferrite --log-level debug README.md
Config File
In config.json:
{
"log_level": "warn"
}
Valid values: debug, info, warn, error, off
Backward Compatibility
- Uses
#[serde(default)]so existing config files withoutlog_leveldefault towarn - Invalid values in config file cause deserialization to use default
- CLI parser accepts aliases:
warning→warn,none→off
Tests
Run log level tests:
cargo test config::settings::tests::test_log_level
Tests cover:
- Default value (
Warn) - Serialization/deserialization
- All enum variants
- Backward compatibility with old config files
- Level filter conversion
Related
- CLI Reference - Full CLI documentation
- Settings & Config - Settings system overview
- GitHub Issue #11 - Original feature request