5 releases

0.2.0 Oct 20, 2025
0.1.5 May 23, 2024
0.1.0 Feb 21, 2024

#186 in Debugging

Download history 322/week @ 2025-07-30 434/week @ 2025-08-06 355/week @ 2025-08-13 217/week @ 2025-08-20 603/week @ 2025-08-27 560/week @ 2025-09-03 519/week @ 2025-09-10 694/week @ 2025-09-17 501/week @ 2025-09-24 629/week @ 2025-10-01 462/week @ 2025-10-08 497/week @ 2025-10-15 400/week @ 2025-10-22 423/week @ 2025-10-29 384/week @ 2025-11-05 394/week @ 2025-11-12

1,677 downloads per month
Used in 72 crates (3 directly)

MIT/Apache

8KB
123 lines

tracing-shared-rs

Share a logger between a dylib/cdylib and the main binary

Usage

[dependencies]
tracing-shared = "0.1"

checkout examples/example.rs

cdylib's case

use tracing_shared::SharedLogger;

fn main() {
    let dylib = unsafe { libloading::Library::new(dylib) }.expect("error loading dylib");
    let setup_logger: FnSetupLogger = unsafe { *dylib.get(b"setup_shared_logger_ref").unwrap() };
    let run: FnRun = unsafe { *dylib.get(b"run").unwrap() };
    let logger = SharedLogger::new();
    setup_logger(&logger);
    run("cdylib")
}

dylib's case

use tracing_shared::SharedLogger;

fn main() {
    let logger = SharedLogger::new();
    example_lib::setup_shared_logger_ref(&logger);
    example_lib::run("dylib");
}

Exported entry points

When you expose functions from your shared library so the host binary can dlsym/GetProcAddress them, add #[no_mangle] to keep the symbol names predictable.

#[no_mangle]
pub fn run(src: &str) {
    println!(
        "{} feature = log is enabled: {}",
        src,
        cfg!(feature = "log")
    );
    println!("{} println!", src);
    tracing::info!("{} tracing::info!", src);
    #[cfg(feature = "log")]
    log::info!("{} log::info!", src);
}

Dependencies

~340–500KB