4 releases

0.1.5 May 23, 2024
0.1.4 May 23, 2024
0.1.3 May 21, 2024
0.1.1 May 20, 2024
0.1.0 Feb 21, 2024

#165 in Debugging

Download history 645/week @ 2024-07-04 652/week @ 2024-07-11 368/week @ 2024-07-18 355/week @ 2024-07-25 204/week @ 2024-08-01 258/week @ 2024-08-08 613/week @ 2024-08-15 435/week @ 2024-08-22 555/week @ 2024-08-29 514/week @ 2024-09-05 508/week @ 2024-09-12 391/week @ 2024-09-19 485/week @ 2024-09-26 409/week @ 2024-10-03 375/week @ 2024-10-10 468/week @ 2024-10-17

1,777 downloads per month
Used in 54 crates (2 directly)

MIT/Apache

10KB
166 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

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")
}

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");
}

Dependencies

~0.4–6MB
~29K SLoC