1
1
import * as shimmer from "shimmer" ;
2
2
import { inspect } from "util" ;
3
3
4
+ type Console = typeof console ;
5
+
6
+ type wrappedConsole = Console & { [ K in LogMethod ] : { __wrapped ?: boolean } } ;
7
+
4
8
import { getLogLevel , LogLevel , setLogLevel } from "../utils/log" ;
5
9
import { TraceContextService } from "./trace-context-service" ;
6
10
@@ -10,7 +14,7 @@ type LogMethod = "log" | "info" | "debug" | "error" | "warn" | "trace";
10
14
* Patches console output to include DataDog's trace context.
11
15
* @param contextService Provides up to date tracing context.
12
16
*/
13
- export function patchConsole ( cnsle : Console , contextService : TraceContextService ) {
17
+ export function patchConsole ( cnsle : wrappedConsole , contextService : TraceContextService ) {
14
18
patchMethod ( cnsle , "log" , contextService ) ;
15
19
patchMethod ( cnsle , "info" , contextService ) ;
16
20
patchMethod ( cnsle , "debug" , contextService ) ;
@@ -31,7 +35,7 @@ export function unpatchConsole(cnsle: Console) {
31
35
unpatchMethod ( cnsle , "trace" ) ;
32
36
}
33
37
34
- function patchMethod ( mod : Console , method : LogMethod , contextService : TraceContextService ) {
38
+ function patchMethod ( mod : wrappedConsole , method : LogMethod , contextService : TraceContextService ) {
35
39
if ( mod [ method ] . __wrapped !== undefined ) {
36
40
return ; // Only patch once
37
41
}
@@ -81,7 +85,7 @@ function patchMethod(mod: Console, method: LogMethod, contextService: TraceConte
81
85
} ;
82
86
} ) ;
83
87
}
84
- function unpatchMethod ( mod : Console , method : LogMethod ) {
88
+ function unpatchMethod ( mod : wrappedConsole , method : LogMethod ) {
85
89
if ( mod [ method ] . __wrapped !== undefined ) {
86
90
shimmer . unwrap ( mod , method ) ;
87
91
}
0 commit comments