Skip to content

Commit 09f65ee

Browse files
sameeragDoğan Erişen
andauthored
Add logging instructions in a separate document (#5663)
* Add logging instructions in a separate document * Update lib/msal-browser/docs/logging.md Co-authored-by: Doğan Erişen <v-derisen@microsoft.com> * Add more details for enabling logs in the browser * Adding PCA context * Update lib/msal-browser/docs/logging.md Co-authored-by: Doğan Erişen <v-derisen@microsoft.com> * Adding appropriate import code for usage example * Correcting the import LogLevel --------- Co-authored-by: Doğan Erişen <v-derisen@microsoft.com>
1 parent f4678bf commit 09f65ee

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
65.6 KB
Loading

lib/msal-browser/docs/logging.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# MSAL JS logging instructions
2+
3+
These are steps needed to enable MSAL JS logging for your applications:
4+
5+
1. In the MSAL [Configuration](./configuration.md) object, you can enable logging to collect msal js logs. We enable different levels of logging and an appropriate level can be chosen as needed.
6+
7+
2. The logger options can be set as below, the example chooses `LogLevel.Trace`
8+
9+
```javascript
10+
11+
import { PublicClientApplication, LogLevel } from "@azure/msal-browser";
12+
13+
const msalConfig = {
14+
auth: {
15+
...
16+
},
17+
cache: {
18+
...
19+
},
20+
system: {
21+
loggerOptions: {
22+
logLevel: LogLevel.Trace,
23+
loggerCallback: (level, message, containsPii) => {
24+
if (containsPii) {
25+
return;
26+
}
27+
switch (level) {
28+
case LogLevel.Error:
29+
console.error(message);
30+
return;
31+
case LogLevel.Info:
32+
console.info(message);
33+
return;
34+
case LogLevel.Verbose:
35+
console.debug(message);
36+
return;
37+
case LogLevel.Warning:
38+
console.warn(message);
39+
return;
40+
default:
41+
console.log(message);
42+
return;
43+
}
44+
}
45+
}
46+
},
47+
48+
...
49+
}
50+
51+
const msalInstance = new PublicClientApplication(msalConfig);
52+
53+
```
54+
55+
An example usage in a sample can be accessed [here](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/VanillaJSTestApp2.0/app/default/authConfig.js#:~:text=logLevel%3A%20msal.LogLevel.Trace%2C).
56+
57+
58+
3. Make sure you have the appropriate log level enabled in your browser console to see these logs, eg: "verbose" may need to be enabled for the browser to load these.
59+
60+
![browser console](./images/BrowserLogEnablement.png)
61+
62+
63+

0 commit comments

Comments
 (0)