nautechsystems/nautilus_trader · error
Invalid log level string: '{s}'
Error message
Invalid log level string: '{s}' What it means
Raised by parse_level_filter_str when a log level string cannot be parsed into a tracing LevelFilter. The input is uppercased (with 'WARNING' mapped to 'WARN') and passed to LevelFilter::from_str; any string not matching a valid level name produces this error wrapping the original input.
Source
Thrown at crates/common/src/logging/mod.rs:232
LogLevel::Debug => LevelFilter::Debug,
LogLevel::Info => LevelFilter::Info,
LogLevel::Warning => LevelFilter::Warn,
LogLevel::Error => LevelFilter::Error,
}
}
/// Parses a string into a [`LevelFilter`].
///
/// # Errors
///
/// Returns an error if the provided string is not a valid `LevelFilter`.
pub fn parse_level_filter_str(s: &str) -> anyhow::Result<LevelFilter> {
let mut log_level_str = s.to_uppercase();
if log_level_str == "WARNING" {
log_level_str = "WARN".to_string();
}
LevelFilter::from_str(&log_level_str)
.map_err(|_| anyhow::anyhow!("Invalid log level string: '{s}'"))
}
/// Parses component-specific log levels from a JSON value map.
///
/// # Errors
///
/// Returns an error if a JSON value in the map is not a string or is not a valid log level.
pub fn parse_component_levels(
original_map: Option<HashMap<String, serde_json::Value>>,
) -> anyhow::Result<AHashMap<Ustr, LevelFilter>> {
let mut new_map = AHashMap::new();
for (key, value) in original_map.unwrap_or_default() {
let ustr_key = Ustr::from(&key);
let s = value.as_str().ok_or_else(|| {
anyhow::anyhow!("Component log level for '{key}' must be a string, was: {value}")
})?;
let lvl = parse_level_filter_str(s)?;View on GitHub (pinned to 18893faf8b)
Solutions
- Use one of the valid level strings: TRACE, DEBUG, INFO, WARN (or WARNING), ERROR, OFF.
- Validate/normalize user or config supplied log levels before passing them to the parser.
- Check for typos or locale/format variations (e.g. 'Info ' with trailing whitespace) in the input.
Example fix
// before
parse_level_filter_str("verbose")?;
// after
parse_level_filter_str("DEBUG")?; Defensive patterns
Strategy: validation
Validate before calling
const VALID_LEVELS: [&str; 6] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF"];
fn is_valid_level(s: &str) -> bool {
let up = s.trim().to_uppercase();
up == "WARNING" || VALID_LEVELS.contains(&up.as_str())
}
assert!(is_valid_level(user_level), "invalid log level: {user_level}"); Prevention
- Validate log level strings against TRACE/DEBUG/INFO/WARN/WARNING/ERROR/OFF before parsing.
- Trim and uppercase user/config supplied levels to avoid case and whitespace issues.
- Centralize level parsing through parse_level_filter_str instead of ad-hoc string matching.
- Document accepted level values wherever log levels are configured.
When it happens
Trigger: Calling parse_level_filter_str with a string other than TRACE/DEBUG/INFO/WARN/WARNING/ERROR/OFF (case-insensitive), e.g. 'verbose', 'log', 'fatal'.
Common situations: Typos or invalid values in RUST_LOG-style environment configuration, log-level entries in a JSON config map for components, or user-supplied CLI log level values.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid log level: {v}
- Component log level for '{key}' must be a string, was: {valu
- Unsupported blockchain {blockchain} for RPC connection
- Kraken Spot does not support the demo environment
- Invalid scientific notation exponent '{exponent}': must be a
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/95ac5aee36138f0f.
Report an issue: GitHub.