pub fn init_logging(verbose: bool, log_format: Option<LogFormat>) -> Result<()>Expand description
Initializes logging infrastructure.
Sets up tracing with appropriate log levels based on verbosity flag.
Writes log messages to stderr, with any embedded URL’s credentials/query string redacted (via
a wrapping Write adapter around the fmt layer’s writer) — this covers rmcp and any other
dependency’s log lines, not just this
project’s own, since a dependency’s tracing output cannot go through this crate’s
Debug/escape_error_text redaction paths.
log_format selects text or JSON output. When None (the flag was not passed),
LogFormat::resolve consults the MCP_EXECUTION_LOG_FORMAT environment variable; an unset
or invalid environment value falls back to text with a WARN-level log line (never echoing
the rejected raw value — see the project’s log-injection hardening for this switch).
Both branches are passed through cap_rmcp_log_level, which caps rmcp’s own tracing
targets at info regardless of the base filter – see that function’s doc comment for why.
§Arguments
verbose- If true, sets log level to DEBUG; otherwise uses INFO or environment variable override viaRUST_LOGlog_format---log-formatflag value, orNoneto consultMCP_EXECUTION_LOG_FORMAT
§Errors
This function cannot fail—it always returns Ok(()). Multiple calls
in the same process will panic rather than returning an error, but this
is not a recoverable condition and indicates a programming error.
§Examples
use mcp_execution_cli::runner;
// `no_run`: this installs a process-global tracing subscriber, which
// panics if called more than once in the same process.
runner::init_logging(false, None)?;