@@ -17,13 +17,24 @@ export abstract class AbstractLogger implements Logger {
17
17
this . context = context ;
18
18
}
19
19
20
+ protected resolveContextString ( context ?: string ) : string {
21
+ if ( this . context ) {
22
+ return context ? `[${ this . context } ] [${ context } ] ` : `[${ this . context } ] ` ;
23
+ }
24
+ return context ? `[${ context } ] ` : '' ;
25
+ }
26
+
27
+ protected resolvePrefix ( context ?: string ) : string {
28
+ const time = new Date ( ) . toISOString ( ) ;
29
+ return `${ time } [${ this . level } ]` ;
30
+ }
31
+
20
32
protected log ( message : any , context ?: string , logFn : ( ...args : any [ ] ) => void = console . info ) : void {
21
33
context = context ?? this . context ;
22
- const time = new Date ( ) . toISOString ( ) ;
23
34
const traceId = this . traceIdProvider ?. provide ( ) ;
24
35
const traceStr = traceId ? ` [trace: ${ traceId } ]` : '' ;
25
- const contextStr = this . context ? ` [ ${ this . context } ]` : '' ;
26
- logFn ( `${ time } [ ${ this . level } ] ${ traceStr } ${ contextStr } ${ message } ` ) ;
36
+ const contextStr = this . resolveContextString ( context ) ;
37
+ logFn ( `${ this . resolvePrefix ( context ) } ${ traceStr } ${ contextStr } ${ message } ` ) ;
27
38
onLogEmitter . fire ( {
28
39
level : this . level ,
29
40
traceId,
@@ -41,7 +52,7 @@ export abstract class AbstractLogger implements Logger {
41
52
if ( start !== undefined ) {
42
53
const duration = Date . now ( ) - start ;
43
54
this . timeRecords . delete ( label ) ;
44
- this . log ( `${ label } : ${ duration } ms` , context ) ;
55
+ this . log ( `${ label } [ ${ duration } ms] ` , context ) ;
45
56
return duration ;
46
57
} else {
47
58
this . log ( `No such label: ${ label } for timeEnd` , context ) ;
0 commit comments