Skip to main content

LogFormat

Enum LogFormat 

Source
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§

§

Text

Human-readable text logs.

§

Json

Structured JSON logs, one object per line.

Implementations§

Source§

impl LogFormat

Source

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");
Source

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);
Source

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);
Source

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("   "));

Trait Implementations§

Source§

impl Clone for LogFormat

Source§

fn clone(&self) -> LogFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LogFormat

Source§

impl Debug for LogFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LogFormat

Source§

fn default() -> LogFormat

Returns the “default value” for a type. Read more
Source§

impl Display for LogFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LogFormat

Source§

impl FromStr for LogFormat

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for LogFormat

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LogFormat

Source§

fn eq(&self, other: &LogFormat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LogFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.