@@ -183,10 +183,10 @@ mod inner {
183
183
use tracing:: { Event , Subscriber } ;
184
184
use tracing_subscriber:: {
185
185
filter:: Directive ,
186
- fmt:: { format, FmtContext , FormatEvent , FormatFields , FormattedFields , Layer } ,
186
+ fmt:: { format, FmtContext , FormatEvent , FormatFields , FormattedFields } ,
187
187
prelude:: * ,
188
188
registry:: LookupSpan ,
189
- EnvFilter ,
189
+ EnvFilter , Layer ,
190
190
} ;
191
191
192
192
// Mainly we disable this for iOS because it causes XCode
@@ -317,51 +317,40 @@ mod inner {
317
317
318
318
let subscriber = tracing_subscriber:: registry ( ) . with ( env_filter) ;
319
319
320
- match noosphere_log_format {
321
- NoosphereLogFormat :: Minimal => {
322
- let subscriber = subscriber. with (
323
- Layer :: default ( ) . event_format ( NoosphereMinimalFormatter :: new (
324
- tracing_subscriber:: fmt:: format ( )
325
- . without_time ( )
326
- . with_target ( false )
327
- . with_ansi ( USE_ANSI_COLORS ) ,
328
- ) ) ,
329
- ) ;
330
-
331
- #[ cfg( feature = "sentry" ) ]
332
- let subscriber = subscriber. with ( sentry_tracing:: layer ( ) ) ;
333
-
334
- subscriber. init ( ) ;
335
- }
320
+ // Erase layer type via Box<dyn> so that we can share common code even
321
+ // if the Layer types are incompatible.
322
+ // See: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/#runtime-configuration-with-layers
323
+ let formatting_layer: Box < dyn Layer < _ > + Send + Sync + ' static > = match noosphere_log_format
324
+ {
325
+ NoosphereLogFormat :: Minimal => Box :: new (
326
+ tracing_subscriber:: fmt:: layer ( ) . event_format ( NoosphereMinimalFormatter :: new (
327
+ tracing_subscriber:: fmt:: format ( )
328
+ . without_time ( )
329
+ . with_target ( false )
330
+ . with_ansi ( USE_ANSI_COLORS ) ,
331
+ ) ) ,
332
+ ) ,
336
333
NoosphereLogFormat :: Verbose => {
337
- let subscriber =
338
- subscriber. with ( tracing_subscriber:: fmt:: layer ( ) . with_ansi ( USE_ANSI_COLORS ) ) ;
339
-
340
- #[ cfg( feature = "sentry" ) ]
341
- let subscriber = subscriber. with ( sentry_tracing:: layer ( ) ) ;
342
-
343
- subscriber. init ( ) ;
334
+ Box :: new ( tracing_subscriber:: fmt:: layer ( ) . with_ansi ( USE_ANSI_COLORS ) )
344
335
}
345
- NoosphereLogFormat :: Pretty => {
346
- let subscriber =
347
- subscriber. with ( Layer :: default ( ) . pretty ( ) . with_ansi ( USE_ANSI_COLORS ) ) ;
348
-
349
- #[ cfg( feature = "sentry" ) ]
350
- let subscriber = subscriber. with ( sentry_tracing:: layer ( ) ) ;
351
-
352
- subscriber. init ( ) ;
353
- }
354
- NoosphereLogFormat :: Structured => {
355
- let subscriber =
356
- subscriber. with ( Layer :: default ( ) . json ( ) . with_ansi ( USE_ANSI_COLORS ) ) ;
336
+ NoosphereLogFormat :: Pretty => Box :: new (
337
+ tracing_subscriber:: fmt:: layer ( )
338
+ . pretty ( )
339
+ . with_ansi ( USE_ANSI_COLORS ) ,
340
+ ) ,
341
+ NoosphereLogFormat :: Structured => Box :: new (
342
+ tracing_subscriber:: fmt:: layer ( )
343
+ . json ( )
344
+ . with_ansi ( USE_ANSI_COLORS ) ,
345
+ ) ,
346
+ } ;
357
347
358
- #[ cfg( feature = "sentry" ) ]
359
- let subscriber = subscriber. with ( sentry_tracing:: layer ( ) ) ;
348
+ let subscriber = subscriber. with ( formatting_layer) ;
360
349
361
- subscriber. init ( ) ;
362
- }
363
- } ;
350
+ #[ cfg( feature = "sentry" ) ]
351
+ let subscriber = subscriber. with ( sentry_tracing:: layer ( ) ) ;
364
352
353
+ subscriber. init ( ) ;
365
354
Ok ( ( ) )
366
355
}
367
356
0 commit comments