pub trait McpLogger:
LoggerDefinition
+ Send
+ Sync {
// Required methods
fn log<'life0, 'async_trait>(
&'life0 self,
level: LoggingLevel,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn set_level<'life0, 'async_trait>(
&'life0 self,
request: SetLevelRequest,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn can_log(&self, level: LoggingLevel) -> bool { ... }
fn priority(&self) -> u32 { ... }
fn validate_data<'life0, 'life1, 'async_trait>(
&'life0 self,
_data: &'life1 Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn transform_data<'life0, 'async_trait>(
&'life0 self,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<Value>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn handle_error<'life0, 'life1, 'async_trait>(
&'life0 self,
error: &'life1 McpError,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
High-level trait for implementing MCP logging
McpLogger extends LoggerDefinition with execution capabilities. All metadata is provided by the LoggerDefinition trait, ensuring consistency between concrete Logger structs and dynamic implementations.
Required Methods§
Sourcefn log<'life0, 'async_trait>(
&'life0 self,
level: LoggingLevel,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn log<'life0, 'async_trait>(
&'life0 self,
level: LoggingLevel,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Log a message (per MCP spec)
This method processes log messages and sends them via the appropriate transport mechanism (notifications/message).
Sourcefn set_level<'life0, 'async_trait>(
&'life0 self,
request: SetLevelRequest,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_level<'life0, 'async_trait>(
&'life0 self,
request: SetLevelRequest,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Set the logging level (per MCP spec)
This method processes logging/setLevel requests to configure the minimum level for log message delivery.
Provided Methods§
Sourcefn can_log(&self, level: LoggingLevel) -> bool
fn can_log(&self, level: LoggingLevel) -> bool
Optional: Check if this logger can handle the given level
This allows for conditional logging based on logger capabilities, transport availability, or other factors.
Sourcefn priority(&self) -> u32
fn priority(&self) -> u32
Optional: Get logger priority for routing
Higher priority loggers are used first when multiple loggers can handle the same message.
Sourcefn validate_data<'life0, 'life1, 'async_trait>(
&'life0 self,
_data: &'life1 Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn validate_data<'life0, 'life1, 'async_trait>(
&'life0 self,
_data: &'life1 Value,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Optional: Validate the log data
This method can perform validation of log data before processing.
Sourcefn transform_data<'life0, 'async_trait>(
&'life0 self,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transform_data<'life0, 'async_trait>(
&'life0 self,
data: Value,
) -> Pin<Box<dyn Future<Output = McpResult<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Optional: Transform log data before sending
This allows for data enrichment, filtering, or formatting before the log message is transmitted.
Sourcefn handle_error<'life0, 'life1, 'async_trait>(
&'life0 self,
error: &'life1 McpError,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle_error<'life0, 'life1, 'async_trait>(
&'life0 self,
error: &'life1 McpError,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Optional: Handle logging errors
This method is called when log delivery fails, allowing for retry logic, fallback logging, or error notifications.