| Crates.io | tracing-shared |
| lib.rs | tracing-shared |
| version | 0.2.0 |
| created_at | 2024-02-21 16:27:45.643241+00 |
| updated_at | 2025-10-20 11:50:34.316805+00 |
| description | Share tracing bwtween dylibs |
| homepage | |
| repository | https://github.com/JakkuSakura/tracing-shared-rs |
| max_upload_size | |
| id | 1148218 |
| size | 16,926 |
Share a logger between a dylib/cdylib and the main binary
[dependencies]
tracing-shared = "0.1"
checkout examples/example.rs
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")
}
use tracing_shared::SharedLogger;
fn main() {
let logger = SharedLogger::new();
example_lib::setup_shared_logger_ref(&logger);
example_lib::run("dylib");
}
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);
}