@@ -82,7 +82,7 @@ pub struct SimpleLogger {
82
82
#[ cfg( feature = "timestamps" ) ]
83
83
timestamps : Timestamps ,
84
84
#[ cfg( feature = "timestamps" ) ]
85
- timeformat : & ' static [ FormatItem < ' static > ] ,
85
+ timeformat : Option < & ' static [ FormatItem < ' static > ] > ,
86
86
87
87
/// Whether to use color output or not.
88
88
///
@@ -113,8 +113,9 @@ impl SimpleLogger {
113
113
114
114
#[ cfg( feature = "timestamps" ) ]
115
115
timestamps : Timestamps :: Utc ,
116
+
116
117
#[ cfg( feature = "timestamps" ) ]
117
- timeformat : time :: macros :: format_description! ( "" ) ,
118
+ timeformat : None ,
118
119
119
120
#[ cfg( feature = "colored" ) ]
120
121
colors : true ,
@@ -285,7 +286,7 @@ impl SimpleLogger {
285
286
#[ must_use = "You must call init() to begin logging" ]
286
287
#[ cfg( feature = "timestamps" ) ]
287
288
pub fn with_custom_timestamps ( mut self , timeformat : & ' static [ FormatItem < ' static > ] ) -> SimpleLogger {
288
- self . timeformat = timeformat;
289
+ self . timeformat = Some ( timeformat) ;
289
290
self
290
291
}
291
292
@@ -345,17 +346,6 @@ impl SimpleLogger {
345
346
#[ cfg( all( windows, feature = "colored" ) ) ]
346
347
set_up_color_terminal ( ) ;
347
348
348
- // Set default timestamp format
349
- #[ cfg( feature = "timestamps" ) ]
350
- if self . timeformat . len ( ) <= 0 {
351
- self . timeformat = match self . timestamps {
352
- Timestamps :: Local => TIMESTAMP_FORMAT_OFFSET ,
353
- Timestamps :: Utc => TIMESTAMP_FORMAT_UTC ,
354
- Timestamps :: UtcOffset ( _) => TIMESTAMP_FORMAT_OFFSET ,
355
- _ => self . timeformat ,
356
- } ;
357
- }
358
-
359
349
/* Sort all module levels from most specific to least specific. The length of the module
360
350
* name is used instead of its actual depth to avoid module name parsing.
361
351
*/
@@ -461,15 +451,20 @@ impl Log for SimpleLogger {
461
451
"behaviour. See the time crate's documentation for more information. " ,
462
452
"(https://time-rs.github.io/internal-api/time/index.html#feature-flags)"
463
453
) )
464
- . format( & self . timeformat)
454
+ . format( & self . timeformat. unwrap_or( TIMESTAMP_FORMAT_OFFSET ) )
455
+ . unwrap( )
456
+ ) ,
457
+ Timestamps :: Utc => format ! (
458
+ "{} " ,
459
+ OffsetDateTime :: now_utc( )
460
+ . format( & self . timeformat. unwrap_or( TIMESTAMP_FORMAT_UTC ) )
465
461
. unwrap( )
466
462
) ,
467
- Timestamps :: Utc => format ! ( "{} " , OffsetDateTime :: now_utc( ) . format( & self . timeformat) . unwrap( ) ) ,
468
463
Timestamps :: UtcOffset ( offset) => format ! (
469
464
"{} " ,
470
465
OffsetDateTime :: now_utc( )
471
466
. to_offset( offset)
472
- . format( & self . timeformat)
467
+ . format( & self . timeformat. unwrap_or ( TIMESTAMP_FORMAT_OFFSET ) )
473
468
. unwrap( )
474
469
) ,
475
470
}
0 commit comments