Skip to content

Commit 9bb5a44

Browse files
authored
Deprecate python logging level setting (#21083)
Deprecates the logging level setting. The default for logging level from VS Code is Info, so in this PR moved a few items to verbose so that we get the same logging experience. Closes #20844
1 parent 05cb255 commit 9bb5a44

File tree

20 files changed

+52
-98
lines changed

20 files changed

+52
-98
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@
922922
},
923923
"python.logging.level": {
924924
"default": "error",
925+
"deprecationMessage": "%python.logging.level.deprecation%",
925926
"description": "%python.logging.level.description%",
926927
"enum": [
927928
"debug",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"python.linting.pylintEnabled.description": "Whether to lint Python files using pylint.",
101101
"python.linting.pylintPath.description": "Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.",
102102
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
103+
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
103104
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
104105
"python.poetryPath.description": "Path to the poetry executable.",
105106
"python.sortImports.args.description": "Arguments passed in. Each argument is a separate item in the array.",

src/client/application/diagnostics/applicationDiagnostics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IWorkspaceService } from '../../common/application/types';
77
import { isTestExecution } from '../../common/constants';
88
import { Resource } from '../../common/types';
99
import { IServiceContainer } from '../../ioc/types';
10-
import { traceInfo, traceLog } from '../../logging';
10+
import { traceLog, traceVerbose } from '../../logging';
1111
import { IApplicationDiagnostics } from '../types';
1212
import { IDiagnostic, IDiagnosticsService, ISourceMapSupportService } from './types';
1313

@@ -21,7 +21,7 @@ function log(diagnostics: IDiagnostic[]): void {
2121
break;
2222
}
2323
default: {
24-
traceInfo(message);
24+
traceVerbose(message);
2525
}
2626
}
2727
});

src/client/common/process/pythonEnvironment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import * as path from 'path';
5-
import { traceError, traceInfo } from '../../logging';
5+
import { traceError, traceVerbose } from '../../logging';
66
import { Conda, CondaEnvironmentInfo } from '../../pythonEnvironments/common/environmentManagers/conda';
77
import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
88
import { InterpreterInformation } from '../../pythonEnvironments/info';
@@ -71,7 +71,7 @@ class PythonEnvironment implements IPythonEnvironment {
7171
try {
7272
data = await this.deps.exec(info.command, info.args);
7373
} catch (ex) {
74-
traceInfo(`Error when getting version of module ${moduleName}`, ex);
74+
traceVerbose(`Error when getting version of module ${moduleName}`, ex);
7575
return undefined;
7676
}
7777
return parse(data.stdout);
@@ -84,7 +84,7 @@ class PythonEnvironment implements IPythonEnvironment {
8484
try {
8585
await this.deps.exec(info.command, info.args);
8686
} catch (ex) {
87-
traceInfo(`Error when checking if module is installed ${moduleName}`, ex);
87+
traceVerbose(`Error when checking if module is installed ${moduleName}`, ex);
8888
return false;
8989
}
9090
return true;
@@ -93,7 +93,7 @@ class PythonEnvironment implements IPythonEnvironment {
9393
private async getInterpreterInformationImpl(): Promise<InterpreterInformation | undefined> {
9494
try {
9595
const python = this.getExecutionInfo();
96-
return await getInterpreterInfo(python, this.deps.shellExec, { info: traceInfo, error: traceError });
96+
return await getInterpreterInfo(python, this.deps.shellExec, { verbose: traceVerbose, error: traceError });
9797
} catch (ex) {
9898
traceError(`Failed to get interpreter information for '${this.pythonPath}'`, ex);
9999
}

src/client/extensionActivation.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { IInterpreterService } from './interpreter/contracts';
3030
import { getLanguageConfiguration } from './language/languageConfiguration';
3131
import { LinterCommands } from './linters/linterCommands';
3232
import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry';
33-
import { setLoggingLevel } from './logging';
3433
import { PythonFormattingEditProvider } from './providers/formatProvider';
3534
import { ReplProvider } from './providers/replProvider';
3635
import { registerTypes as providersRegisterTypes } from './providers/serviceRegistry';
@@ -47,7 +46,6 @@ import * as pythonEnvironments from './pythonEnvironments';
4746
import { ActivationResult, ExtensionState } from './components';
4847
import { Components } from './extensionInit';
4948
import { setDefaultLanguageServer } from './activation/common/defaultlanguageServer';
50-
import { getLoggingLevel } from './logging/settings';
5149
import { DebugService } from './common/application/debugService';
5250
import { DebugSessionEventDispatcher } from './debugger/extension/hooks/eventHandlerDispatcher';
5351
import { IDebugSessionEventHandlers } from './debugger/extension/hooks/types';
@@ -137,11 +135,6 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
137135
const extensions = serviceContainer.get<IExtensions>(IExtensions);
138136
await setDefaultLanguageServer(extensions, serviceManager);
139137

140-
// Note we should not trigger any extension related code which logs, until we have set logging level. So we cannot
141-
// use configurations service to get level setting. Instead, we use Workspace service to query for setting as it
142-
// directly queries VSCode API.
143-
setLoggingLevel(getLoggingLevel());
144-
145138
const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
146139
// Settings are dependent on Experiment service, so we need to initialize it after experiments are activated.
147140
serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings().register();

src/client/interpreter/activation/service.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ import { EventName } from '../../telemetry/constants';
2525
import { IInterpreterService } from '../contracts';
2626
import { IEnvironmentActivationService } from './types';
2727
import { TraceOptions } from '../../logging/types';
28-
import {
29-
traceDecoratorError,
30-
traceDecoratorVerbose,
31-
traceError,
32-
traceInfo,
33-
traceVerbose,
34-
traceWarn,
35-
} from '../../logging';
28+
import { traceDecoratorError, traceDecoratorVerbose, traceError, traceVerbose, traceWarn } from '../../logging';
3629
import { Conda } from '../../pythonEnvironments/common/environmentManagers/conda';
3730
import { StopWatch } from '../../common/utils/stopWatch';
3831
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector';
@@ -290,7 +283,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
290283
// that's the case, wait and try again. This happens especially on AzDo
291284
const excString = (exc as Error).toString();
292285
if (condaRetryMessages.find((m) => excString.includes(m)) && tryCount < 10) {
293-
traceInfo(`Conda is busy, attempting to retry ...`);
286+
traceVerbose(`Conda is busy, attempting to retry ...`);
294287
result = undefined;
295288
tryCount += 1;
296289
await sleep(500);

src/client/logging/index.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { StopWatch } from '../common/utils/stopWatch';
1111
import { sendTelemetryEvent } from '../telemetry';
1212
import { EventName } from '../telemetry/constants';
1313
import { FileLogger } from './fileLogger';
14-
import { Arguments, ILogging, LoggingLevelSettingType, LogLevel, TraceDecoratorType, TraceOptions } from './types';
14+
import { Arguments, ILogging, LogLevel, TraceDecoratorType, TraceOptions } from './types';
1515
import { argsToLogString, returnValueToLogString } from './util';
1616

1717
const DEFAULT_OPTS: TraceOptions = TraceOptions.Arguments | TraceOptions.ReturnValue;
@@ -26,21 +26,6 @@ export function registerLogger(logger: ILogging): Disposable {
2626
};
2727
}
2828

29-
const logLevelMap: Map<string | undefined, LogLevel> = new Map([
30-
['error', LogLevel.Error],
31-
['warn', LogLevel.Warn],
32-
['info', LogLevel.Info],
33-
['debug', LogLevel.Debug],
34-
['none', LogLevel.Off],
35-
['off', LogLevel.Off],
36-
[undefined, LogLevel.Error],
37-
]);
38-
39-
let globalLoggingLevel: LogLevel;
40-
export function setLoggingLevel(level?: LoggingLevelSettingType): void {
41-
globalLoggingLevel = logLevelMap.get(level) ?? LogLevel.Error;
42-
}
43-
4429
export function initializeFileLogging(disposables: Disposable[]): void {
4530
if (process.env.VSC_PYTHON_LOG_FILE) {
4631
const fileLogger = new FileLogger(createWriteStream(process.env.VSC_PYTHON_LOG_FILE));
@@ -54,27 +39,19 @@ export function traceLog(...args: Arguments): void {
5439
}
5540

5641
export function traceError(...args: Arguments): void {
57-
if (globalLoggingLevel >= LogLevel.Error) {
58-
loggers.forEach((l) => l.traceError(...args));
59-
}
42+
loggers.forEach((l) => l.traceError(...args));
6043
}
6144

6245
export function traceWarn(...args: Arguments): void {
63-
if (globalLoggingLevel >= LogLevel.Warn) {
64-
loggers.forEach((l) => l.traceWarn(...args));
65-
}
46+
loggers.forEach((l) => l.traceWarn(...args));
6647
}
6748

6849
export function traceInfo(...args: Arguments): void {
69-
if (globalLoggingLevel >= LogLevel.Info) {
70-
loggers.forEach((l) => l.traceInfo(...args));
71-
}
50+
loggers.forEach((l) => l.traceInfo(...args));
7251
}
7352

7453
export function traceVerbose(...args: Arguments): void {
75-
if (globalLoggingLevel >= LogLevel.Debug) {
76-
loggers.forEach((l) => l.traceVerbose(...args));
77-
}
54+
loggers.forEach((l) => l.traceVerbose(...args));
7855
}
7956

8057
/** Logging Decorators go here */
@@ -89,7 +66,7 @@ export function traceDecoratorInfo(message: string): TraceDecoratorType {
8966
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Info });
9067
}
9168
export function traceDecoratorWarn(message: string): TraceDecoratorType {
92-
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Warn });
69+
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Warning });
9370
}
9471

9572
// Information about a function/method call.
@@ -223,7 +200,7 @@ export function logTo(logLevel: LogLevel, ...args: Arguments): void {
223200
case LogLevel.Error:
224201
traceError(...args);
225202
break;
226-
case LogLevel.Warn:
203+
case LogLevel.Warning:
227204
traceWarn(...args);
228205
break;
229206
case LogLevel.Info:

src/client/logging/settings.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/client/logging/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
/* eslint-disable @typescript-eslint/ban-types */
55
/* eslint-disable @typescript-eslint/no-explicit-any */
66

7-
export type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug';
7+
export type Arguments = unknown[];
8+
89
export enum LogLevel {
910
Off = 0,
10-
Error = 10,
11-
Warn = 20,
12-
Info = 30,
13-
Debug = 40,
11+
Trace = 1,
12+
Debug = 2,
13+
Info = 3,
14+
Warning = 4,
15+
Error = 5,
1416
}
1517

16-
export type Arguments = unknown[];
17-
1818
export interface ILogging {
1919
traceLog(...data: Arguments): void;
2020
traceError(...data: Arguments): void;

src/client/pythonEnvironments/base/info/environmentInfoService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createDeferred, Deferred, sleep } from '../../../common/utils/async';
77
import { createRunningWorkerPool, IWorkerPool, QueuePosition } from '../../../common/utils/workerPool';
88
import { getInterpreterInfo, InterpreterInformation } from './interpreter';
99
import { buildPythonExecInfo } from '../../exec';
10-
import { traceError, traceInfo, traceWarn } from '../../../logging';
10+
import { traceError, traceVerbose, traceWarn } from '../../../logging';
1111
import { Conda, CONDA_ACTIVATION_TIMEOUT, isCondaEnvironment } from '../../common/environmentManagers/conda';
1212
import { PythonEnvInfo, PythonEnvKind } from '.';
1313
import { normCasePath } from '../../common/externalDependencies';
@@ -153,7 +153,7 @@ class EnvironmentInfoService implements IEnvironmentInfoService {
153153
// as complete env info may not be available at this time.
154154
const isCondaEnv = env.kind === PythonEnvKind.Conda || (await isCondaEnvironment(env.executable.filename));
155155
if (isCondaEnv) {
156-
traceInfo(
156+
traceVerbose(
157157
`Validating ${env.executable.filename} normally failed with error, falling back to using conda run: (${reason})`,
158158
);
159159
if (this.condaRunWorkerPool === undefined) {

src/client/pythonEnvironments/base/info/interpreter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
InterpreterInfoJson,
99
} from '../../../common/process/internal/scripts';
1010
import { Architecture } from '../../../common/utils/platform';
11-
import { traceError, traceInfo } from '../../../logging';
11+
import { traceError, traceVerbose } from '../../../logging';
1212
import { shellExecute } from '../../common/externalDependencies';
1313
import { copyPythonExecInfo, PythonExecInfo } from '../../exec';
1414
import { parseVersion } from './pythonVersion';
@@ -102,6 +102,6 @@ export async function getInterpreterInfo(
102102
traceError(`Failed to parse interpreter information for >> ${quoted} << with ${ex}`);
103103
return undefined;
104104
}
105-
traceInfo(`Found interpreter for >> ${quoted} <<: ${JSON.stringify(json)}`);
105+
traceVerbose(`Found interpreter for >> ${quoted} <<: ${JSON.stringify(json)}`);
106106
return extractInterpreterInfo(python.pythonExecutable, json);
107107
}

src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { Event } from 'vscode';
55
import { isTestExecution } from '../../../../common/constants';
6-
import { traceInfo, traceVerbose } from '../../../../logging';
6+
import { traceVerbose } from '../../../../logging';
77
import { arePathsSame, getFileInfo, pathExists } from '../../../common/externalDependencies';
88
import { PythonEnvInfo, PythonEnvKind } from '../../info';
99
import { areEnvsDeepEqual, areSameEnv, getEnvPath } from '../../info/env';
@@ -225,7 +225,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
225225
await this.persistentStorage.store(envs);
226226
return;
227227
}
228-
traceInfo('Environments added to cache', JSON.stringify(this.envs));
228+
traceVerbose('Environments added to cache', JSON.stringify(this.envs));
229229
this.markAllEnvsAsFlushed();
230230
await this.persistentStorage.store(this.envs);
231231
}

src/client/pythonEnvironments/creation/provider/venvCreationProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createVenvScript } from '../../../common/process/internal/scripts';
88
import { execObservable } from '../../../common/process/rawProcessApis';
99
import { createDeferred } from '../../../common/utils/async';
1010
import { Common, CreateEnv } from '../../../common/utils/localize';
11-
import { traceError, traceInfo, traceLog } from '../../../logging';
11+
import { traceError, traceLog, traceVerbose } from '../../../logging';
1212
import { CreateEnvironmentProgress } from '../types';
1313
import { pickWorkspaceFolder } from '../common/workspaceSelection';
1414
import { IInterpreterQuickPick } from '../../../interpreter/configuration/types';
@@ -208,7 +208,7 @@ export class VenvCreationProvider implements CreateEnvironmentProvider {
208208
throw ex;
209209
}
210210
if (!installInfo) {
211-
traceInfo('Virtual env creation exited during dependencies selection.');
211+
traceVerbose('Virtual env creation exited during dependencies selection.');
212212
return MultiStepAction.Cancel;
213213
}
214214
}

src/client/pythonEnvironments/creation/provider/venvUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CancellationToken, QuickPickItem, RelativePattern, WorkspaceFolder } fr
99
import { CreateEnv } from '../../../common/utils/localize';
1010
import { MultiStepAction, MultiStepNode, showQuickPickWithBack } from '../../../common/vscodeApis/windowApis';
1111
import { findFiles } from '../../../common/vscodeApis/workspaceApis';
12-
import { traceError, traceInfo, traceVerbose } from '../../../logging';
12+
import { traceError, traceVerbose } from '../../../logging';
1313

1414
const exclude = '**/{.venv*,.git,.nox,.tox,.conda,site-packages,__pypackages__}/**';
1515
async function getPipRequirementsFiles(
@@ -133,10 +133,10 @@ export async function pickPackagesToInstall(
133133
hasBuildSystem = tomlHasBuildSystem(toml);
134134

135135
if (!hasBuildSystem) {
136-
traceInfo('Create env: Found toml without build system. So we will not use editable install.');
136+
traceVerbose('Create env: Found toml without build system. So we will not use editable install.');
137137
}
138138
if (extras.length === 0) {
139-
traceInfo('Create env: Found toml without optional dependencies.');
139+
traceVerbose('Create env: Found toml without optional dependencies.');
140140
}
141141
} else if (context === MultiStepAction.Back) {
142142
// This step is not really used so just go back

src/client/pythonEnvironments/info/interpreter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function extractInterpreterInfo(python: string, raw: InterpreterInfoJson): Inter
4848
}
4949

5050
type Logger = {
51-
info(msg: string): void;
51+
verbose(msg: string): void;
5252
error(msg: string): void;
5353
};
5454

@@ -85,7 +85,7 @@ export async function getInterpreterInfo(
8585
}
8686
const json = parse(result.stdout);
8787
if (logger) {
88-
logger.info(`Found interpreter for ${argv}`);
88+
logger.verbose(`Found interpreter for ${argv}`);
8989
}
9090
if (!json) {
9191
return undefined;

0 commit comments

Comments
 (0)