@@ -8,38 +8,6 @@ static MAX_LEVEL: OnceLock<Level> = OnceLock::new();
88static FOREIGN_LOGGER : OnceLock < Box < dyn AppServicesLogger > > = OnceLock :: new ( ) ;
99static GLOBAL_SUBSCRIBER : Once = Once :: new ( ) ;
1010
11- // The "targets" (in practice, crate names) which are hooked up to the `tracing` crate for logging.
12- // We should improve this, or better still, just kill this crate entirely and move to using
13- // tracing-support directly, like we (plan to) do on Desktop.
14- //
15- // Note also that it is a natural consequence of using `tracing` that each target must be explicitly listened for
16- // *somewhere*, otherwise logs from that target will not be seen. For now, that list of targets is here, but
17- // when we move to tracing-support it's likely this list will be pushed down into the clients (so that each
18- // target can optionally be handled differently from the others).
19- static TRACING_TARGETS : & [ & str ] = & [
20- "autofill" ,
21- "error_support" ,
22- "fxa-client" ,
23- "init_rust_components" ,
24- "interrupt_support" ,
25- "logins" ,
26- "merino" ,
27- "nimbus" ,
28- "places" ,
29- "push" ,
30- "rate-limiter" ,
31- "rc_crypto" ,
32- "relevancy" ,
33- "remote_settings" ,
34- "search" ,
35- "sql_support" ,
36- "suggest" ,
37- "sync_manager" ,
38- "sync15" ,
39- "tabs" ,
40- "viaduct" ,
41- ] ;
42-
4311#[ derive( uniffi:: Record , Debug , PartialEq , Eq ) ]
4412pub struct Record {
4513 pub level : Level ,
@@ -90,7 +58,8 @@ pub trait AppServicesLogger: Sync + Send {
9058
9159/// Set the logger to forward to.
9260///
93- /// Pass in None to disable logging.
61+ /// Once a logger is passed in, it cannot be changed.
62+ /// However, you can pass in `None` to disable logging.
9463#[ uniffi:: export]
9564pub fn set_logger ( logger : Option < Box < dyn AppServicesLogger > > ) {
9665 GLOBAL_SUBSCRIBER . call_once ( || {
@@ -102,13 +71,13 @@ pub fn set_logger(logger: Option<Box<dyn AppServicesLogger>>) {
10271
10372 let level = MAX_LEVEL . get_or_init ( || Level :: Debug ) ;
10473 let sink = Arc :: new ( ForwarderEventSink { } ) ;
105- // Set up a tracing subscriber for crates which use tracing and forward to the foreign log forwarder.
106- for target in TRACING_TARGETS {
107- tracing_support:: register_event_sink ( target, ( * level) . into ( ) , sink. clone ( ) )
108- }
109- // if called before we just ignore the error for now, and also ignored if they supply None.
11074 if let Some ( logger) = logger {
75+ // Set up a tracing subscriber for crates which use tracing and forward to the foreign log forwarder.
76+ tracing_support:: register_min_level_event_sink ( ( * level) . into ( ) , sink. clone ( ) ) ;
77+ // Set the `FOREIGN_LOGGER` global. If this was called before we just ignore the error.
11178 FOREIGN_LOGGER . set ( logger) . ok ( ) ;
79+ } else {
80+ tracing_support:: unregister_min_level_event_sink ( ) ;
11281 }
11382}
11483
0 commit comments