Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Logging

zero-mysql uses the tracing crate for logging and instrumentation.

Setup

Add tracing-subscriber to your dependencies:

[dependencies]
tracing-subscriber = "0.3"

Initialize the subscriber:

tracing_subscriber::fmt::init();

Log Levels

  • WARN: Connection errors and protocol issues
  • DEBUG: Query execution details
  • TRACE: Low-level protocol packets

Example

use tracing_subscriber;

fn main() {
    // Initialize logging
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();

    let mut conn = Conn::new("mysql://localhost")?;
    conn.query_drop("SELECT 1")?;  // Will log query execution
}

Performance Note

In release builds, tracing macros above WARN level are compiled out via the release_max_level_warn feature for minimal runtime overhead.