Logging and Debugging

nmrs uses the log crate for structured logging. You can enable logging to see what nmrs is doing internally, which is invaluable for debugging connection issues.

Enabling Logging

nmrs produces log messages but doesn't configure a logger — that's up to your application. The simplest option is env_logger:

[dependencies]
nmrs = "2.2"
env_logger = "0.11"
log = "0.4"
use nmrs::NetworkManager;

#[tokio::main]
async fn main() -> nmrs::Result<()> {
    env_logger::init();

    let nm = NetworkManager::new().await?;
    nm.scan_networks().await?;

    Ok(())
}

Run with:

RUST_LOG=nmrs=debug cargo run

Log Levels

LevelContent
errorConnection failures, D-Bus errors
warnUnexpected states, fallback behavior
infoConnection events, state transitions
debugD-Bus method calls, scan results, settings
traceRaw D-Bus messages, detailed internal state

Level Examples

# Only errors
RUST_LOG=nmrs=error cargo run

# Info and above
RUST_LOG=nmrs=info cargo run

# Full debug output
RUST_LOG=nmrs=debug cargo run

# Everything including D-Bus internals
RUST_LOG=nmrs=trace cargo run

# Debug nmrs + info for zbus
RUST_LOG=nmrs=debug,zbus=info cargo run

Debugging Connection Issues

When a connection fails, enable debug logging to see the full sequence:

RUST_LOG=nmrs=debug cargo run

This will show:

  • Which device was selected
  • Whether a saved connection was found
  • The settings dictionary sent to NetworkManager
  • State transitions during activation
  • The specific error or reason for failure

Debugging D-Bus Issues

If you suspect a D-Bus communication problem, enable trace logging for both nmrs and zbus:

RUST_LOG=nmrs=trace,zbus=debug cargo run

You can also use system tools:

# Monitor NetworkManager D-Bus traffic
sudo dbus-monitor --system "interface='org.freedesktop.NetworkManager'"

# Check NetworkManager journal logs
journalctl -u NetworkManager -f

# Check wpa_supplicant logs (for Wi-Fi auth issues)
journalctl -u wpa_supplicant -f

Using with Other Loggers

nmrs works with any logger that implements the log facade:

tracing (with compatibility layer)

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
tracing-log = "0.2"
use tracing_subscriber;

fn main() {
    tracing_subscriber::fmt()
        .with_env_filter("nmrs=debug")
        .init();
    // ...
}

simplelog

[dependencies]
simplelog = "0.12"
use simplelog::*;

fn main() {
    TermLogger::init(
        LevelFilter::Debug,
        Config::default(),
        TerminalMode::Mixed,
        ColorChoice::Auto,
    ).unwrap();
    // ...
}

Next Steps