pub enum LogFormat {
Text,
Json,
}Expand description
Diagnostic log output format.
Selects whether mcp-execution-cli and mcp-execution-server emit human-readable text logs
or structured JSON logs. Independent of OutputFormat, which controls command result
output, not diagnostic logging.
§Examples
use mcp_execution_core::cli::LogFormat;
let format = LogFormat::Json;
assert_eq!(format.as_str(), "json");
let format: LogFormat = "TEXT".parse().unwrap();
assert_eq!(format, LogFormat::Text);Variants§
Implementations§
Source§impl LogFormat
impl LogFormat
Sourcepub const fn as_str(&self) -> &'static str
pub const fn as_str(&self) -> &'static str
Returns the string representation of the format.
§Examples
use mcp_execution_core::cli::LogFormat;
assert_eq!(LogFormat::Text.as_str(), "text");
assert_eq!(LogFormat::Json.as_str(), "json");Sourcepub fn resolve(flag: Option<Self>, env_value: Option<&str>) -> Self
pub fn resolve(flag: Option<Self>, env_value: Option<&str>) -> Self
Resolves the effective log format from an optional CLI flag value and an optional raw environment variable value.
Precedence: flag wins unconditionally when set — env_value is not even inspected, so a
malformed environment value has no effect on the result once the flag has already resolved
the format. Otherwise the env value is parsed via LogFormat::parse_env, which treats
an empty/whitespace-only or unrecognized value alike as “no override” and falls back to
LogFormat::default.
Returns only the resolved format, not the rejected raw value: neither production caller
logs it (a raw MCP_EXECUTION_LOG_FORMAT value is untrusted external input, and echoing
it — even truncated — would open a log-injection vector), so carrying it through this
return type would be a capability with no real consumer. A caller that needs to know
whether the env value was invalid specifically (as opposed to merely absent), e.g. to
decide whether to log a warning, calls LogFormat::is_invalid_env_value separately.
Deliberately free of std::env access itself: callers pass
std::env::var(LOG_FORMAT_ENV_VAR).ok() in, which keeps precedence and fallback behavior
testable without mutating process environment state. One accepted consequence of that
call shape: a non-UTF-8 MCP_EXECUTION_LOG_FORMAT value folds to Err(VarError::NotUnicode(_)),
hence None here, so it is silently treated as unset rather than invalid — unlike a
valid-UTF-8 but unrecognized value (e.g. "xml"), which LogFormat::is_invalid_env_value
does flag for a caller to warn about. Not worth switching callers to std::env::var_os to
close this gap: a non-UTF-8 value is exceedingly unlikely for a variable whose only valid
values are ASCII, and the failure mode (no warning, falls back to the same default a bad
value would) is identical either way.
§Examples
use mcp_execution_core::cli::LogFormat;
// The flag wins even over a valid env value.
assert_eq!(LogFormat::resolve(Some(LogFormat::Json), Some("text")), LogFormat::Json);
// No flag: a valid env value is used, case-insensitively.
assert_eq!(LogFormat::resolve(None, Some("JSON")), LogFormat::Json);
// No flag, unrecognized env value: falls back to the default (`Text`).
assert_eq!(LogFormat::resolve(None, Some("xml")), LogFormat::Text);Sourcepub fn parse_env(raw: &str) -> Option<Self>
pub fn parse_env(raw: &str) -> Option<Self>
Parses a raw MCP_EXECUTION_LOG_FORMAT environment-variable value.
Returns None uniformly for an empty/whitespace-only value and for one that doesn’t
match text/json (case-insensitive) — both are “no override” as far as resolve
is concerned. Use LogFormat::is_invalid_env_value when the two None cases need to
be told apart (e.g. to decide whether a caller should warn about a rejected value).
§Examples
use mcp_execution_core::cli::LogFormat;
assert_eq!(LogFormat::parse_env("json"), Some(LogFormat::Json));
assert_eq!(LogFormat::parse_env("JSON"), Some(LogFormat::Json));
assert_eq!(LogFormat::parse_env(""), None);
assert_eq!(LogFormat::parse_env(" "), None);
assert_eq!(LogFormat::parse_env("xml"), None);Sourcepub fn is_invalid_env_value(raw: &str) -> bool
pub fn is_invalid_env_value(raw: &str) -> bool
True when raw is a genuinely invalid MCP_EXECUTION_LOG_FORMAT value — non-empty and
not parseable via LogFormat::parse_env — as opposed to an empty/whitespace-only value,
which is merely “unset” and not worth warning about. Lets a caller decide whether to emit
a warning without re-implementing parse_env’s own emptiness
check.
§Examples
use mcp_execution_core::cli::LogFormat;
assert!(LogFormat::is_invalid_env_value("xml"));
assert!(!LogFormat::is_invalid_env_value("json"));
assert!(!LogFormat::is_invalid_env_value(""));
assert!(!LogFormat::is_invalid_env_value(" "));