File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 17
17
18
18
use std:: fmt:: Debug ;
19
19
20
+ use log:: Level ;
20
21
use serde:: { Deserialize , Serialize } ;
21
22
use strum:: { Display , EnumIter , EnumString , FromRepr } ;
22
23
@@ -292,6 +293,18 @@ impl From<u8> for LogColor {
292
293
}
293
294
}
294
295
296
+ impl From < Level > for LogColor {
297
+ fn from ( value : Level ) -> Self {
298
+ match value {
299
+ Level :: Error => Self :: Red ,
300
+ Level :: Warn => Self :: Yellow ,
301
+ Level :: Info => Self :: Green ,
302
+ Level :: Debug => Self :: Blue ,
303
+ Level :: Trace => Self :: Normal ,
304
+ }
305
+ }
306
+ }
307
+
295
308
/// An ANSI log line format specifier.
296
309
/// This is used for formatting log messages with ANSI escape codes.
297
310
#[ repr( C ) ]
Original file line number Diff line number Diff line change @@ -292,19 +292,20 @@ impl Log for Logger {
292
292
} else {
293
293
get_atomic_clock_static ( ) . get_time_ns ( )
294
294
} ;
295
+ let level = record. level ( ) ;
295
296
let key_values = record. key_values ( ) ;
296
- let color = key_values
297
+ let color: LogColor = key_values
297
298
. get ( "color" . into ( ) )
298
299
. and_then ( |v| v. to_u64 ( ) . map ( |v| ( v as u8 ) . into ( ) ) )
299
- . unwrap_or ( LogColor :: Normal ) ;
300
+ . unwrap_or ( level . into ( ) ) ;
300
301
let component = key_values. get ( "component" . into ( ) ) . map_or_else (
301
302
|| Ustr :: from ( record. metadata ( ) . target ( ) ) ,
302
303
|v| Ustr :: from ( & v. to_string ( ) ) ,
303
304
) ;
304
305
305
306
let line = LogLine {
306
307
timestamp,
307
- level : record . level ( ) ,
308
+ level,
308
309
color,
309
310
component,
310
311
message : format ! ( "{}" , record. args( ) ) ,
You can’t perform that action at this time.
0 commit comments