@@ -17,19 +17,23 @@ import * as winston from 'winston';
17
17
import { TransformableInfo } from 'logform' ;
18
18
19
19
const coloredTemplate = ( info : TransformableInfo ) => {
20
- const { timestamp, level, message, plugin, service } = info ;
20
+ const { timestamp, level, message, plugin, service, ... fields } = info ;
21
21
const colorizer = winston . format . colorize ( ) ;
22
22
const prefix = plugin || service ;
23
23
const timestampColor = colorizer . colorize ( 'timestamp' , timestamp ) ;
24
24
const prefixColor = colorizer . colorize ( 'prefix' , prefix ) ;
25
25
26
- return `${ timestampColor } ${ prefixColor } ${ level } ${ message } ` ;
26
+ const extraFields = Object . entries ( fields )
27
+ . map ( ( [ key , value ] ) => `${ colorizer . colorize ( 'field' , `${ key } ` ) } =${ value } ` )
28
+ . join ( ' ' ) ;
29
+
30
+ return `${ timestampColor } ${ prefixColor } ${ level } ${ message } ${ extraFields } ` ;
27
31
} ;
28
32
29
33
export const coloredFormat = winston . format . combine (
30
34
winston . format . timestamp ( ) ,
31
35
winston . format . colorize ( {
32
- colors : { timestamp : 'dim' , prefix : 'blue' } ,
36
+ colors : { timestamp : 'dim' , prefix : 'blue' , field : 'cyan' } ,
33
37
} ) ,
34
38
winston . format . printf ( coloredTemplate ) ,
35
39
) ;
0 commit comments