Path: blob/main/extensions/microsoft-authentication/src/common/loggerOptions.ts
3320 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { LogLevel as MsalLogLevel } from '@azure/msal-node';6import { env, LogLevel, LogOutputChannel } from 'vscode';7import { MicrosoftAuthenticationTelemetryReporter } from './telemetryReporter';89export class MsalLoggerOptions {10piiLoggingEnabled = false;1112constructor(13private readonly _output: LogOutputChannel,14private readonly _telemtryReporter: MicrosoftAuthenticationTelemetryReporter15) { }1617get logLevel(): MsalLogLevel {18return this._toMsalLogLevel(env.logLevel);19}2021loggerCallback(level: MsalLogLevel, message: string, _containsPii: boolean): void {2223// Log to output channel one level lower than the MSAL log level24switch (level) {25case MsalLogLevel.Error:26this._output.error(message);27this._telemtryReporter.sendTelemetryErrorEvent(message);28return;29case MsalLogLevel.Warning:30this._output.warn(message);31return;32case MsalLogLevel.Info:33this._output.debug(message);34return;35case MsalLogLevel.Verbose:36this._output.trace(message);37return;38case MsalLogLevel.Trace:39// Do not log trace messages40return;41default:42this._output.debug(message);43return;44}45}4647private _toMsalLogLevel(logLevel: LogLevel): MsalLogLevel {48switch (logLevel) {49case LogLevel.Trace:50return MsalLogLevel.Trace;51case LogLevel.Debug:52return MsalLogLevel.Verbose;53case LogLevel.Info:54return MsalLogLevel.Info;55case LogLevel.Warning:56return MsalLogLevel.Warning;57case LogLevel.Error:58return MsalLogLevel.Error;59default:60return MsalLogLevel.Info;61}62}63}646566