Skip to content

Commit 1263f6d

Browse files
committed
check in with function to create debugger
1 parent 0ef1d44 commit 1263f6d

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

packages/teams-js/src/internal/globalVars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export class GlobalVars {
99
public static hostClientType: string | undefined = undefined;
1010
public static clientSupportedSDKVersion: string;
1111
public static printCapabilityEnabled = false;
12+
public static turnOnConsoleLog = false;
1213
}

packages/teams-js/src/internal/telemetry.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { debug as registerLogger, Debugger } from 'debug';
22

3+
import { GlobalVars } from './globalVars';
34
import { UUID } from './uuidObject';
45

56
// Each teamsjs instance gets a unique identifier that will be prepended to every log statement
@@ -12,7 +13,70 @@ registerLogger.formatArgs = function (args) {
1213
originalFormatArgsFunction.call(this, args);
1314
};
1415

15-
const topLevelLogger = registerLogger('teamsJs');
16+
const createDebuggerFunction = (namespace: string): Debugger => {
17+
let internalDebugger: Debugger = registerLogger(namespace);
18+
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
const func = function (formatter: any, ...args: any[]): void {
21+
if (GlobalVars.turnOnConsoleLog) {
22+
console.log(formatter, args);
23+
}
24+
internalDebugger(formatter, args);
25+
} as Debugger;
26+
27+
Object.assign(func, {
28+
color: {
29+
get() {
30+
return internalDebugger.color;
31+
},
32+
set(value: string) {
33+
internalDebugger.color = value;
34+
},
35+
},
36+
diff: {
37+
get() {
38+
return internalDebugger.diff;
39+
},
40+
set(value: number) {
41+
internalDebugger.diff = value;
42+
},
43+
},
44+
enabled: {
45+
get(): boolean {
46+
return internalDebugger.enabled;
47+
},
48+
set(enabled: boolean) {
49+
internalDebugger.enabled = enabled;
50+
},
51+
},
52+
namespace: {
53+
get(): string {
54+
return internalDebugger.namespace;
55+
},
56+
set(namespace: string) {
57+
internalDebugger.namespace = namespace;
58+
},
59+
},
60+
extend: {
61+
value(namespace: string, delimiter?: string) {
62+
internalDebugger = internalDebugger.extend(namespace, delimiter);
63+
return this;
64+
},
65+
},
66+
log: {
67+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
68+
value(...args: any[]) {
69+
internalDebugger.log(args);
70+
},
71+
},
72+
});
73+
74+
return func;
75+
};
76+
77+
const topLevelLogger = createDebuggerFunction('teamsJs');
78+
79+
// const topLevelLogger = registerLogger('teamsJs');
1680

1781
/**
1882
* @internal

0 commit comments

Comments
 (0)