Skip to content

Commit ac0ded4

Browse files
committed
fix(sdk-swift): Respect logging settings in ClientConfig
1 parent 9940c59 commit ac0ded4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

bindings/prose-sdk-ffi/src/client.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ pub trait ClientDelegate: Send + Sync {
3636

3737
#[derive(uniffi::Record)]
3838
pub struct ClientConfig {
39-
#[uniffi(default = false)]
40-
pub log_received_stanzas: bool,
41-
#[uniffi(default = false)]
42-
pub log_sent_stanzas: bool,
4339
#[uniffi(default = false)]
4440
pub logging_enabled: bool,
4541
#[uniffi(default = "trace")]
@@ -52,10 +48,8 @@ pub struct ClientConfig {
5248
impl Default for ClientConfig {
5349
fn default() -> Self {
5450
ClientConfig {
55-
log_received_stanzas: false,
56-
log_sent_stanzas: false,
5751
logging_enabled: true,
58-
logging_min_level: "trace".to_string(),
52+
logging_min_level: "warn".to_string(),
5953
client_name: env!("CARGO_PKG_NAME").to_string(),
6054
client_version: env!("CARGO_PKG_VERSION").to_string(),
6155
client_os: None,
@@ -76,10 +70,19 @@ impl Client {
7670
delegate: Option<Arc<dyn ClientDelegate>>,
7771
config: Option<ClientConfig>,
7872
) -> ClientResult<Self> {
79-
let oslog_layer = OsLogger::new("org.prose", "default")
80-
.with_filter(LevelFilter::from_level(Level::TRACE));
73+
let config = config.unwrap_or_default();
8174

82-
Registry::default().with(oslog_layer).init();
75+
if config.logging_enabled {
76+
let min_level = config.logging_min_level.parse::<Level>();
77+
match min_level {
78+
Ok(level) => {
79+
let oslog_layer = OsLogger::new("org.prose", "default")
80+
.with_filter(LevelFilter::from_level(level));
81+
Registry::default().with(oslog_layer).init()
82+
}
83+
Err(_) => println!("Invalid logging level {}.", config.logging_min_level),
84+
}
85+
}
8386

8487
let cache_path = cache_dir.into_inner();
8588
let cache_dir = Path::new(&cache_path);
@@ -90,7 +93,6 @@ impl Client {
9093
delegate.map(|d| Box::new(DelegateWrapper(d)) as Box<dyn CoreClientDelegate>);
9194

9295
let store = open_store(PlatformDriver::new(cache_dir.join("ProseDB.sqlite"))).await?;
93-
let config = config.unwrap_or_default();
9496

9597
let software_version = SoftwareVersion {
9698
name: config.client_name.clone(),

0 commit comments

Comments
 (0)