tracing-shared

Crates.iotracing-shared
lib.rstracing-shared
version0.1.5
sourcesrc
created_at2024-02-21 16:27:45.643241
updated_at2024-05-23 11:40:52.05928
descriptionShare tracing bwtween dylibs
homepage
repositoryhttps://github.com/JakkuSakura/tracing-shared-rs
max_upload_size
id1148218
size29,942
Jakku Sakura (JakkuSakura)

documentation

README

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");
}
Commit count: 12

cargo fmt