Skip to content

Commit

Permalink
fix logger for bindings (#1605)
Browse files Browse the repository at this point in the history
* fix logger for bindings

* lints
  • Loading branch information
insipx authored Feb 6, 2025
1 parent 233cc25 commit b137466
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
7 changes: 4 additions & 3 deletions bindings_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ rand.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"] }
uniffi = { version = "0.28.0", features = ["bindgen-tests"] }
uuid = { workspace = true, features = ["v4", "fast-rng"] }
xmtp_api_grpc = { path = "../xmtp_api_grpc", features = ["test-utils"] }
xmtp_mls = { path = "../xmtp_mls", features = ["test-utils"] }
xmtp_proto = { path = "../xmtp_proto", features = ["test-utils"] }
xmtp_api_grpc = { workspace = true, features = ["test-utils"] }
xmtp_mls = { workspace = true, features = ["test-utils"] }
xmtp_proto = { workspace = true, features = ["test-utils"] }
xmtp_common = { workspace = true, features = ["test-utils"] }

[features]
bench = ["xmtp_mls/bench", "xmtp_common/bench", "dep:criterion", "dep:fdlimit"]
Expand Down
39 changes: 36 additions & 3 deletions bindings_ffi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,35 @@ mod ios {
}
}

#[cfg(not(any(target_os = "ios", target_os = "android")))]
// production logger for anything not ios/android mobile
#[cfg(not(any(target_os = "ios", target_os = "android", test)))]
pub use other::*;
#[cfg(not(any(target_os = "ios", target_os = "android")))]
#[cfg(not(any(target_os = "ios", target_os = "android", test)))]
mod other {
use super::*;

pub fn native_layer<S>() -> impl Layer<S>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
xmtp_common::logger_layer()
use tracing_subscriber::{
fmt::{self, format},
EnvFilter, Layer,
};
let filter = EnvFilter::builder()
.with_default_directive(tracing::metadata::LevelFilter::INFO.into())
.from_env_lossy();
fmt::layer()
.compact()
.fmt_fields({
format::debug_fn(move |writer, field, value| {
if field.name() == "message" {
write!(writer, "{:?}", value)?;
}
Ok(())
})
})
.with_filter(filter)
}
}

Expand All @@ -57,3 +75,18 @@ pub fn init_logger() {
let _ = tracing_subscriber::registry().with(native_layer).try_init();
});
}

#[cfg(test)]
pub use test_logger::*;

#[cfg(test)]
mod test_logger {
use super::*;

pub fn native_layer<S>() -> impl Layer<S>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
xmtp_common::logger_layer()
}
}

0 comments on commit b137466

Please sign in to comment.