Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/microsoft-authentication/src/common/loggerOptions.ts
3320 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { LogLevel as MsalLogLevel } from '@azure/msal-node';
7
import { env, LogLevel, LogOutputChannel } from 'vscode';
8
import { MicrosoftAuthenticationTelemetryReporter } from './telemetryReporter';
9
10
export class MsalLoggerOptions {
11
piiLoggingEnabled = false;
12
13
constructor(
14
private readonly _output: LogOutputChannel,
15
private readonly _telemtryReporter: MicrosoftAuthenticationTelemetryReporter
16
) { }
17
18
get logLevel(): MsalLogLevel {
19
return this._toMsalLogLevel(env.logLevel);
20
}
21
22
loggerCallback(level: MsalLogLevel, message: string, _containsPii: boolean): void {
23
24
// Log to output channel one level lower than the MSAL log level
25
switch (level) {
26
case MsalLogLevel.Error:
27
this._output.error(message);
28
this._telemtryReporter.sendTelemetryErrorEvent(message);
29
return;
30
case MsalLogLevel.Warning:
31
this._output.warn(message);
32
return;
33
case MsalLogLevel.Info:
34
this._output.debug(message);
35
return;
36
case MsalLogLevel.Verbose:
37
this._output.trace(message);
38
return;
39
case MsalLogLevel.Trace:
40
// Do not log trace messages
41
return;
42
default:
43
this._output.debug(message);
44
return;
45
}
46
}
47
48
private _toMsalLogLevel(logLevel: LogLevel): MsalLogLevel {
49
switch (logLevel) {
50
case LogLevel.Trace:
51
return MsalLogLevel.Trace;
52
case LogLevel.Debug:
53
return MsalLogLevel.Verbose;
54
case LogLevel.Info:
55
return MsalLogLevel.Info;
56
case LogLevel.Warning:
57
return MsalLogLevel.Warning;
58
case LogLevel.Error:
59
return MsalLogLevel.Error;
60
default:
61
return MsalLogLevel.Info;
62
}
63
}
64
}
65
66