diff --git a/Cargo.toml b/Cargo.toml index 53210e20..0dedb4cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,14 @@ description = "C-to-rustls bindings" edition = "2018" links = "rustls_ffi" +[features] +# Enable this feature when building as Rust dependency. It inhibits the +# default behavior of capturing the global logger, which only works when +# built using the Makefile, which passes -C metadata=rustls-ffi to avoid +# interfering with copies of the global logger brought in by other Rust +# libraries. +no_log_capture = [] + [dependencies] # Keep in sync with RUSTLS_CRATE_VERSION in build.rs rustls = { version = "=0.20", features = [ "dangerous_configuration" ] } diff --git a/src/log.rs b/src/log.rs index 6337d85c..332679f2 100644 --- a/src/log.rs +++ b/src/log.rs @@ -30,6 +30,10 @@ impl log::Log for Logger { fn flush(&self) {} } +#[cfg(feature = "no_log_capture")] +pub(crate) fn ensure_log_registered() {} + +#[cfg(not(feature = "no_log_capture"))] pub(crate) fn ensure_log_registered() { log::set_logger(&Logger {}).ok(); log::set_max_level(log::LevelFilter::Debug)