55
66use std:: fs;
77use std:: path:: Path ;
8- use std:: sync:: Arc ;
8+ use std:: sync:: { Arc , Once } ;
99
1010use crate :: types:: {
1111 AccountInfo , Availability , Avatar , ClientResult , ConnectionError , PresenceSubRequest ,
@@ -36,10 +36,6 @@ pub trait ClientDelegate: Send + Sync {
3636
3737#[ derive( uniffi:: Record ) ]
3838pub struct ClientConfig {
39- #[ uniffi( default = false ) ]
40- pub logging_enabled : bool ,
41- #[ uniffi( default = "trace" ) ]
42- pub logging_min_level : String ,
4339 pub client_name : String ,
4440 pub client_version : String ,
4541 pub client_os : Option < String > ,
@@ -48,15 +44,15 @@ pub struct ClientConfig {
4844impl Default for ClientConfig {
4945 fn default ( ) -> Self {
5046 ClientConfig {
51- logging_enabled : true ,
52- logging_min_level : "warn" . to_string ( ) ,
5347 client_name : env ! ( "CARGO_PKG_NAME" ) . to_string ( ) ,
5448 client_version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
5549 client_os : None ,
5650 }
5751 }
5852}
5953
54+ static INIT_LOGGER : Once = Once :: new ( ) ;
55+
6056#[ derive( uniffi:: Object ) ]
6157pub struct Client {
6258 client : CoreClient ,
@@ -72,18 +68,6 @@ impl Client {
7268 ) -> ClientResult < Self > {
7369 let config = config. unwrap_or_default ( ) ;
7470
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.core" , "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- }
86-
8771 let cache_path = cache_dir. into_inner ( ) ;
8872 let cache_dir = Path :: new ( & cache_path) ;
8973 info ! ( "Caching data at {:?}" , cache_dir) ;
@@ -115,6 +99,20 @@ impl Client {
11599
116100 Ok ( Client { client } )
117101 }
102+
103+ pub fn enable_logging ( & self , min_level : & str ) {
104+ INIT_LOGGER . call_once ( || {
105+ let parsed_min_level = min_level. parse :: < Level > ( ) ;
106+ match parsed_min_level {
107+ Ok ( level) => {
108+ let oslog_layer = OsLogger :: new ( "org.prose.core" , "default" )
109+ . with_filter ( LevelFilter :: from_level ( level) ) ;
110+ Registry :: default ( ) . with ( oslog_layer) . init ( )
111+ }
112+ Err ( _) => println ! ( "Invalid logging level {}." , min_level) ,
113+ }
114+ } )
115+ }
118116}
119117
120118#[ uniffi:: export( async_runtime = "tokio" ) ]
0 commit comments