pub trait LogHandler:
Send
+ Sync
+ Debug {
// Required method
fn handle_log<'life0, 'async_trait>(
&'life0 self,
log: LogMessage,
) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Handler for server log messages
Log handlers receive log messages from the server and can route them to the client’s logging system. This is useful for debugging, monitoring, and maintaining a unified log across client and server.
§Examples
use turbomcp_client::handlers::{LogHandler, LogMessage, HandlerResult};
use turbomcp_protocol::types::LogLevel;
use async_trait::async_trait;
#[derive(Debug)]
struct TraceLogHandler;
#[async_trait]
impl LogHandler for TraceLogHandler {
async fn handle_log(&self, log: LogMessage) -> HandlerResult<()> {
match log.level {
LogLevel::Error => tracing::error!("Server: {}", log.message),
LogLevel::Warning => tracing::warn!("Server: {}", log.message),
LogLevel::Info => tracing::info!("Server: {}", log.message),
LogLevel::Debug => tracing::debug!("Server: {}", log.message),
LogLevel::Notice => tracing::info!("Server: {}", log.message),
LogLevel::Critical => tracing::error!("Server CRITICAL: {}", log.message),
LogLevel::Alert => tracing::error!("Server ALERT: {}", log.message),
LogLevel::Emergency => tracing::error!("Server EMERGENCY: {}", log.message),
}
Ok(())
}
}
Required Methods§
Sourcefn handle_log<'life0, 'async_trait>(
&'life0 self,
log: LogMessage,
) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_log<'life0, 'async_trait>(
&'life0 self,
log: LogMessage,
) -> Pin<Box<dyn Future<Output = HandlerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a log message from the server
This method is called when the server sends log messages to the client. Implementations can route these to the client’s logging system.
§Arguments
log
- The log message with level, content, and metadata
§Returns
Returns Ok(())
if the log message was processed successfully.