From 244ea1607d0caafe84ca79cc13ecad8c227a762a Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 14 Nov 2021 09:38:51 -0800 Subject: [PATCH] Add feature to inhibit log capture (#219) This is necessary to work properly when built as a Rust dependency (a rare use case). --- Cargo.toml | 8 ++++++++ src/log.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 29a4b543..2706c1ad 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)