Skip to main content

Module session_logging

Module session_logging 

Source
Expand description

Per-session structured logging

This module provides session-aware structured logging for all protocol servers (SMTP, IMAP, POP3, JMAP). Each connection gets a unique session ID that is attached to all log events, making it easy to trace and debug individual sessions.

§Features

  • Unique session IDs (UUID v4)
  • Session context with client IP, protocol, and user information
  • Integration with tracing-subscriber for structured logging
  • Helper macros for convenient session-aware logging
  • Automatic span management per session

§Example

use rusmes_server::session_logging::{SessionContext, SessionLogger};
use std::net::IpAddr;

let session = SessionContext::new(
    IpAddr::from([127, 0, 0, 1]),
    "SMTP",
);

let logger = SessionLogger::new(session);
let _guard = logger.enter();

// All logs within this span will include session context
tracing::info!("Connection established");

Structs§

SessionContext
Session context for structured logging
SessionLogger
Session-aware logger that wraps tracing spans

Functions§

format_session_header
Helper function to format session context for response headers
format_session_json
Create a JSON representation of session context