Skip to content

Commit 0f935e3

Browse files
authored
Added the teamsjs instance identifier and timestamp to every log line (#2524)
* Log TJS instance and timestamp on all log statements * Logging working * changefile * Update format of log statements * Rename variable
1 parent d169af3 commit 0f935e3

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Added logging for current teamsjs instance and timestamps",
4+
"packageName": "@microsoft/teams-js",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

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

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

3+
import { UUID } from './uuidObject';
4+
5+
// Each teamsjs instance gets a unique identifier that will be prepended to every log statement
6+
export const teamsJsInstanceIdentifier = new UUID();
7+
8+
// Every log statement will get prepended with the teamsJsInstanceIdentifier and a timestamp
9+
const originalFormatArgsFunction = registerLogger.formatArgs;
10+
registerLogger.formatArgs = function (args) {
11+
args[0] = `(${new Date().toISOString()}): ${args[0]} [${teamsJsInstanceIdentifier.toString()}]`;
12+
originalFormatArgsFunction.call(this, args);
13+
};
14+
315
const topLevelLogger = registerLogger('teamsJs');
416

517
/**

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,17 +750,19 @@ export namespace app {
750750
const scriptUsageWarning =
751751
'Today, teamsjs can only be used from a single script or you may see undefined behavior. This log line is used to help detect cases where teamsjs is loaded multiple times -- it is always written. The presence of the log itself does not indicate a multi-load situation, but multiples of these log lines will. If you would like to use teamjs from more than one script at the same time, please open an issue at https://github.com/OfficeDev/microsoft-teams-library-js/issues';
752752
if (!currentScriptSrc || currentScriptSrc.length === 0) {
753-
appLogger(
754-
'teamsjs version %s is being used from a script tag embedded directly in your html. %s',
755-
version,
756-
scriptUsageWarning,
757-
);
753+
appLogger('teamsjs is being used from a script tag embedded directly in your html. %s', scriptUsageWarning);
758754
} else {
759-
appLogger('teamsjs version %s is being used from %s. %s', version, currentScriptSrc, scriptUsageWarning);
755+
appLogger('teamsjs is being used from %s. %s', currentScriptSrc, scriptUsageWarning);
760756
}
761757
}
762758

763-
// This is called right away to make sure that we capture which script is being executed correctly
759+
// This is called right away to make sure that we capture which script is being executed and important stats about the current teamsjs instance
760+
appLogger(
761+
'teamsjs instance is version %s, starting at %s UTC (%s local)',
762+
version,
763+
new Date().toISOString(),
764+
new Date().toLocaleString(),
765+
);
764766
logWhereTeamsJsIsBeingUsed();
765767

766768
/**

0 commit comments

Comments
 (0)