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

#157 in Debugging

Download history 358/week @ 2024-07-22 194/week @ 2024-07-29 185/week @ 2024-08-05 675/week @ 2024-08-12 379/week @ 2024-08-19 427/week @ 2024-08-26 692/week @ 2024-09-02 415/week @ 2024-09-09 482/week @ 2024-09-16 481/week @ 2024-09-23 347/week @ 2024-09-30 369/week @ 2024-10-07 525/week @ 2024-10-14 384/week @ 2024-10-21 369/week @ 2024-10-28 473/week @ 2024-11-04

1,773 downloads per month
Used in 56 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.3–6MB
~29K SLoC