11import * as shimmer from "shimmer" ;
22import { inspect } from "util" ;
33
4+ type Console = typeof console ;
5+
6+ type wrappedConsole = Console & { [ K in LogMethod ] : { __wrapped ?: boolean } } ;
7+
48import { getLogLevel , LogLevel , setLogLevel } from "../utils/log" ;
59import { TraceContextService } from "./trace-context-service" ;
610
@@ -10,7 +14,7 @@ type LogMethod = "log" | "info" | "debug" | "error" | "warn" | "trace";
1014 * Patches console output to include DataDog's trace context.
1115 * @param contextService Provides up to date tracing context.
1216 */
13- export function patchConsole ( cnsle : Console , contextService : TraceContextService ) {
17+ export function patchConsole ( cnsle : wrappedConsole , contextService : TraceContextService ) {
1418 patchMethod ( cnsle , "log" , contextService ) ;
1519 patchMethod ( cnsle , "info" , contextService ) ;
1620 patchMethod ( cnsle , "debug" , contextService ) ;
@@ -31,7 +35,7 @@ export function unpatchConsole(cnsle: Console) {
3135 unpatchMethod ( cnsle , "trace" ) ;
3236}
3337
34- function patchMethod ( mod : Console , method : LogMethod , contextService : TraceContextService ) {
38+ function patchMethod ( mod : wrappedConsole , method : LogMethod , contextService : TraceContextService ) {
3539 if ( mod [ method ] . __wrapped !== undefined ) {
3640 return ; // Only patch once
3741 }
@@ -81,7 +85,7 @@ function patchMethod(mod: Console, method: LogMethod, contextService: TraceConte
8185 } ;
8286 } ) ;
8387}
84- function unpatchMethod ( mod : Console , method : LogMethod ) {
88+ function unpatchMethod ( mod : wrappedConsole , method : LogMethod ) {
8589 if ( mod [ method ] . __wrapped !== undefined ) {
8690 shimmer . unwrap ( mod , method ) ;
8791 }
0 commit comments