Skip to content

Commit

Permalink
Add feature to inhibit log capture (#219)
Browse files Browse the repository at this point in the history
This is necessary to work properly when built as a Rust dependency (a
rare use case).
  • Loading branch information
jsha authored Nov 14, 2021
1 parent 59765f3 commit 244ea16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand Down
4 changes: 4 additions & 0 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 244ea16

Please sign in to comment.