Skip to content

Commit 2b22c7d

Browse files
committed
update anonymous function for log
1 parent 2be11ab commit 2b22c7d

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { logger } from '@microsoft/teams-js';
2+
import React, { ReactElement } from 'react';
3+
4+
import { ApiWithoutInput } from './utils';
5+
import { ModuleWrapper } from './utils/ModuleWrapper';
6+
7+
const TurnOnConsoleLog = (): React.ReactElement =>
8+
ApiWithoutInput({
9+
name: 'turnOnConsoleLog',
10+
title: 'Turn On Console Log',
11+
onClick: async () => {
12+
logger.turnOnConsoleLog();
13+
return 'true';
14+
},
15+
});
16+
17+
const TurnOffConsoleLog = (): React.ReactElement =>
18+
ApiWithoutInput({
19+
name: 'turnOffConsoleLog',
20+
title: 'Turn Off Console Log',
21+
onClick: async () => {
22+
logger.turnOffConsoleLog();
23+
return 'true';
24+
},
25+
});
26+
const LoggerAPIs = (): ReactElement => (
27+
<ModuleWrapper title="Logger">
28+
<TurnOnConsoleLog />
29+
<TurnOffConsoleLog />
30+
</ModuleWrapper>
31+
);
32+
33+
export default LoggerAPIs;

apps/teams-test-app/src/pages/TestApp.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import GeoLocationAPIs from '../components/GeoLocationAPIs';
2222
import HostEntityTabAPIs from '../components/HostEntityTabAPIs';
2323
import Links from '../components/Links';
2424
import LocationAPIs from '../components/LocationAPIs';
25+
import LoggerAPIs from '../components/LoggerAPIs';
2526
import LogAPIs from '../components/LogsAPIs';
2627
import MailAPIs from '../components/MailAPIs';
2728
import MarketplaceAPIs from '../components/MarketplaceAPIs';
@@ -124,6 +125,7 @@ export const TestApp: React.FC = () => {
124125
<Links />
125126
<LocationAPIs />
126127
<LogAPIs />
128+
<LoggerAPIs />
127129
<MailAPIs />
128130
<MarketplaceAPIs />
129131
<MediaAPIs />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const createDebuggerFunction = (namespace: string): Debugger => {
2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2121
const func = function (formatter: any, ...args: any[]): void {
2222
if (GlobalVars.turnOnConsoleLog) {
23+
internalDebugger(formatter, args);
2324
console.log(formatter, args);
2425
}
25-
internalDebugger(formatter, args);
2626
} as Debugger;
2727

2828
Object.assign(func, {

packages/teams-js/src/public/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,4 @@ export { settings } from './settings';
119119
export { tasks } from './tasks';
120120
export { liveShare, LiveShareHost } from './liveShareHost';
121121
export { marketplace } from './marketplace';
122+
export { logger } from './logger';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { GlobalVars } from '../internal/globalVars';
2+
3+
export namespace logger {
4+
/**
5+
* todo: doc
6+
* @returns bool
7+
*/
8+
export function turnOnConsoleLog(): boolean {
9+
GlobalVars.turnOnConsoleLog = true;
10+
return GlobalVars.turnOnConsoleLog;
11+
}
12+
13+
/**
14+
* todo: doc
15+
* @returns bool
16+
*/
17+
export function turnOffConsoleLog(): boolean {
18+
GlobalVars.turnOnConsoleLog = false;
19+
return GlobalVars.turnOnConsoleLog;
20+
}
21+
}

0 commit comments

Comments
 (0)