@@ -231,22 +231,9 @@ impl Builder {
231
231
} else {
232
232
Box :: new ( move |buf, record| {
233
233
let fmt = DefaultFormatWriter {
234
- timestamp : built. default_format . timestamp ,
235
- module_path : built. default_format . module_path ,
236
- target : built. default_format . target ,
237
- level : built. default_format . level ,
238
- written_header_value : false ,
239
- indent : built. default_format . indent ,
240
- suffix : built. default_format . suffix ,
241
- source_file : built. default_format . source_file ,
242
- source_line_number : built. default_format . source_line_number ,
243
- #[ cfg( feature = "kv" ) ]
244
- kv_format : built
245
- . default_format
246
- . kv_format
247
- . as_deref ( )
248
- . unwrap_or ( & default_kv_format) ,
234
+ format : & built. default_format ,
249
235
buf,
236
+ written_header_value : false ,
250
237
} ;
251
238
252
239
fmt. write ( record)
@@ -321,18 +308,9 @@ impl Default for DefaultFormat {
321
308
///
322
309
/// This format needs to work with any combination of crate features.
323
310
struct DefaultFormatWriter < ' a > {
324
- timestamp : Option < TimestampPrecision > ,
325
- module_path : bool ,
326
- target : bool ,
327
- level : bool ,
328
- source_file : bool ,
329
- source_line_number : bool ,
330
- written_header_value : bool ,
331
- indent : Option < usize > ,
311
+ format : & ' a DefaultFormat ,
332
312
buf : & ' a mut Formatter ,
333
- suffix : & ' a str ,
334
- #[ cfg( feature = "kv" ) ]
335
- kv_format : & ' a KvFormatFn ,
313
+ written_header_value : bool ,
336
314
}
337
315
338
316
impl DefaultFormatWriter < ' _ > {
@@ -347,7 +325,7 @@ impl DefaultFormatWriter<'_> {
347
325
self . write_args ( record) ?;
348
326
#[ cfg( feature = "kv" ) ]
349
327
self . write_kv ( record) ?;
350
- write ! ( self . buf, "{}" , self . suffix)
328
+ write ! ( self . buf, "{}" , self . format . suffix)
351
329
}
352
330
353
331
fn subtle_style ( & self , text : & ' static str ) -> SubtleStyle {
@@ -383,7 +361,7 @@ impl DefaultFormatWriter<'_> {
383
361
}
384
362
385
363
fn write_level ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
386
- if !self . level {
364
+ if !self . format . level {
387
365
return Ok ( ( ) ) ;
388
366
}
389
367
@@ -409,7 +387,7 @@ impl DefaultFormatWriter<'_> {
409
387
#[ cfg( feature = "humantime" ) ]
410
388
{
411
389
use self :: TimestampPrecision :: { Micros , Millis , Nanos , Seconds } ;
412
- let ts = match self . timestamp {
390
+ let ts = match self . format . timestamp {
413
391
None => return Ok ( ( ) ) ,
414
392
Some ( Seconds ) => self . buf . timestamp_seconds ( ) ,
415
393
Some ( Millis ) => self . buf . timestamp_millis ( ) ,
@@ -429,7 +407,7 @@ impl DefaultFormatWriter<'_> {
429
407
}
430
408
431
409
fn write_module_path ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
432
- if !self . module_path {
410
+ if !self . format . module_path {
433
411
return Ok ( ( ) ) ;
434
412
}
435
413
@@ -441,12 +419,16 @@ impl DefaultFormatWriter<'_> {
441
419
}
442
420
443
421
fn write_source_location ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
444
- if !self . source_file {
422
+ if !self . format . source_file {
445
423
return Ok ( ( ) ) ;
446
424
}
447
425
448
426
if let Some ( file_path) = record. file ( ) {
449
- let line = self . source_line_number . then ( || record. line ( ) ) . flatten ( ) ;
427
+ let line = self
428
+ . format
429
+ . source_line_number
430
+ . then ( || record. line ( ) )
431
+ . flatten ( ) ;
450
432
match line {
451
433
Some ( line) => self . write_header_value ( format_args ! ( "{file_path}:{line}" ) ) ,
452
434
None => self . write_header_value ( file_path) ,
@@ -457,7 +439,7 @@ impl DefaultFormatWriter<'_> {
457
439
}
458
440
459
441
fn write_target ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
460
- if !self . target {
442
+ if !self . format . target {
461
443
return Ok ( ( ) ) ;
462
444
}
463
445
@@ -477,7 +459,7 @@ impl DefaultFormatWriter<'_> {
477
459
}
478
460
479
461
fn write_args ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
480
- match self . indent {
462
+ match self . format . indent {
481
463
// Fast path for no indentation
482
464
None => write ! ( self . buf, "{}" , record. args( ) ) ,
483
465
@@ -497,7 +479,7 @@ impl DefaultFormatWriter<'_> {
497
479
write ! (
498
480
self . fmt. buf,
499
481
"{}{:width$}" ,
500
- self . fmt. suffix,
482
+ self . fmt. format . suffix,
501
483
"" ,
502
484
width = self . indent_count
503
485
) ?;
@@ -530,7 +512,11 @@ impl DefaultFormatWriter<'_> {
530
512
531
513
#[ cfg( feature = "kv" ) ]
532
514
fn write_kv ( & mut self , record : & Record < ' _ > ) -> io:: Result < ( ) > {
533
- let format = self . kv_format ;
515
+ let format = self
516
+ . format
517
+ . kv_format
518
+ . as_deref ( )
519
+ . unwrap_or ( & default_kv_format) ;
534
520
format ( self . buf , record. key_values ( ) )
535
521
}
536
522
}
0 commit comments