Skip to main content

init_logging

Function init_logging 

Source
pub fn init_logging(args: &Args) -> Result<Option<WorkerGuard>>
Expand description

Initialize logging based on configuration arguments.

This function sets up tracing subscribers with:

  • Environment-based log level filtering (falls back to args.log_level)
  • Stderr output in text format (stdout is reserved for MCP protocol)
  • Optional file logging with rotation support

§Returns

  • Ok(Some(WorkerGuard)) - File logging enabled, guard must be kept alive
  • Ok(None) - No file logging configured
  • Err(SshMcpError) - Configuration or IO error

§Note

The WorkerGuard must be stored for the entire program lifetime when file logging is enabled, or the background worker will be dropped and logs may be lost.