Skip to content

Deprecate python logging level setting #21083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@
},
"python.logging.level": {
"default": "error",
"deprecationMessage": "%python.logging.level.deprecation%",
"description": "%python.logging.level.description%",
"enum": [
"debug",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"python.linting.pylintEnabled.description": "Whether to lint Python files using pylint.",
"python.linting.pylintPath.description": "Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.",
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
"python.poetryPath.description": "Path to the poetry executable.",
"python.sortImports.args.description": "Arguments passed in. Each argument is a separate item in the array.",
Expand Down
4 changes: 2 additions & 2 deletions src/client/application/diagnostics/applicationDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IWorkspaceService } from '../../common/application/types';
import { isTestExecution } from '../../common/constants';
import { Resource } from '../../common/types';
import { IServiceContainer } from '../../ioc/types';
import { traceInfo, traceLog } from '../../logging';
import { traceLog, traceVerbose } from '../../logging';
import { IApplicationDiagnostics } from '../types';
import { IDiagnostic, IDiagnosticsService, ISourceMapSupportService } from './types';

Expand All @@ -21,7 +21,7 @@ function log(diagnostics: IDiagnostic[]): void {
break;
}
default: {
traceInfo(message);
traceVerbose(message);
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/client/common/process/pythonEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as path from 'path';
import { traceError, traceInfo } from '../../logging';
import { traceError, traceVerbose } from '../../logging';
import { Conda, CondaEnvironmentInfo } from '../../pythonEnvironments/common/environmentManagers/conda';
import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
import { InterpreterInformation } from '../../pythonEnvironments/info';
Expand Down Expand Up @@ -71,7 +71,7 @@ class PythonEnvironment implements IPythonEnvironment {
try {
data = await this.deps.exec(info.command, info.args);
} catch (ex) {
traceInfo(`Error when getting version of module ${moduleName}`, ex);
traceVerbose(`Error when getting version of module ${moduleName}`, ex);
return undefined;
}
return parse(data.stdout);
Expand All @@ -84,7 +84,7 @@ class PythonEnvironment implements IPythonEnvironment {
try {
await this.deps.exec(info.command, info.args);
} catch (ex) {
traceInfo(`Error when checking if module is installed ${moduleName}`, ex);
traceVerbose(`Error when checking if module is installed ${moduleName}`, ex);
return false;
}
return true;
Expand All @@ -93,7 +93,7 @@ class PythonEnvironment implements IPythonEnvironment {
private async getInterpreterInformationImpl(): Promise<InterpreterInformation | undefined> {
try {
const python = this.getExecutionInfo();
return await getInterpreterInfo(python, this.deps.shellExec, { info: traceInfo, error: traceError });
return await getInterpreterInfo(python, this.deps.shellExec, { verbose: traceVerbose, error: traceError });
} catch (ex) {
traceError(`Failed to get interpreter information for '${this.pythonPath}'`, ex);
}
Expand Down
7 changes: 0 additions & 7 deletions src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { IInterpreterService } from './interpreter/contracts';
import { getLanguageConfiguration } from './language/languageConfiguration';
import { LinterCommands } from './linters/linterCommands';
import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry';
import { setLoggingLevel } from './logging';
import { PythonFormattingEditProvider } from './providers/formatProvider';
import { ReplProvider } from './providers/replProvider';
import { registerTypes as providersRegisterTypes } from './providers/serviceRegistry';
Expand All @@ -47,7 +46,6 @@ import * as pythonEnvironments from './pythonEnvironments';
import { ActivationResult, ExtensionState } from './components';
import { Components } from './extensionInit';
import { setDefaultLanguageServer } from './activation/common/defaultlanguageServer';
import { getLoggingLevel } from './logging/settings';
import { DebugService } from './common/application/debugService';
import { DebugSessionEventDispatcher } from './debugger/extension/hooks/eventHandlerDispatcher';
import { IDebugSessionEventHandlers } from './debugger/extension/hooks/types';
Expand Down Expand Up @@ -137,11 +135,6 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
const extensions = serviceContainer.get<IExtensions>(IExtensions);
await setDefaultLanguageServer(extensions, serviceManager);

// Note we should not trigger any extension related code which logs, until we have set logging level. So we cannot
// use configurations service to get level setting. Instead, we use Workspace service to query for setting as it
// directly queries VSCode API.
setLoggingLevel(getLoggingLevel());

const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
// Settings are dependent on Experiment service, so we need to initialize it after experiments are activated.
serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings().register();
Expand Down
11 changes: 2 additions & 9 deletions src/client/interpreter/activation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ import { EventName } from '../../telemetry/constants';
import { IInterpreterService } from '../contracts';
import { IEnvironmentActivationService } from './types';
import { TraceOptions } from '../../logging/types';
import {
traceDecoratorError,
traceDecoratorVerbose,
traceError,
traceInfo,
traceVerbose,
traceWarn,
} from '../../logging';
import { traceDecoratorError, traceDecoratorVerbose, traceError, traceVerbose, traceWarn } from '../../logging';
import { Conda } from '../../pythonEnvironments/common/environmentManagers/conda';
import { StopWatch } from '../../common/utils/stopWatch';
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector';
Expand Down Expand Up @@ -290,7 +283,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
// that's the case, wait and try again. This happens especially on AzDo
const excString = (exc as Error).toString();
if (condaRetryMessages.find((m) => excString.includes(m)) && tryCount < 10) {
traceInfo(`Conda is busy, attempting to retry ...`);
traceVerbose(`Conda is busy, attempting to retry ...`);
result = undefined;
tryCount += 1;
await sleep(500);
Expand Down
37 changes: 7 additions & 30 deletions src/client/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { StopWatch } from '../common/utils/stopWatch';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
import { FileLogger } from './fileLogger';
import { Arguments, ILogging, LoggingLevelSettingType, LogLevel, TraceDecoratorType, TraceOptions } from './types';
import { Arguments, ILogging, LogLevel, TraceDecoratorType, TraceOptions } from './types';
import { argsToLogString, returnValueToLogString } from './util';

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

const logLevelMap: Map<string | undefined, LogLevel> = new Map([
['error', LogLevel.Error],
['warn', LogLevel.Warn],
['info', LogLevel.Info],
['debug', LogLevel.Debug],
['none', LogLevel.Off],
['off', LogLevel.Off],
[undefined, LogLevel.Error],
]);

let globalLoggingLevel: LogLevel;
export function setLoggingLevel(level?: LoggingLevelSettingType): void {
globalLoggingLevel = logLevelMap.get(level) ?? LogLevel.Error;
}

export function initializeFileLogging(disposables: Disposable[]): void {
if (process.env.VSC_PYTHON_LOG_FILE) {
const fileLogger = new FileLogger(createWriteStream(process.env.VSC_PYTHON_LOG_FILE));
Expand All @@ -54,27 +39,19 @@ export function traceLog(...args: Arguments): void {
}

export function traceError(...args: Arguments): void {
if (globalLoggingLevel >= LogLevel.Error) {
loggers.forEach((l) => l.traceError(...args));
}
loggers.forEach((l) => l.traceError(...args));
}

export function traceWarn(...args: Arguments): void {
if (globalLoggingLevel >= LogLevel.Warn) {
loggers.forEach((l) => l.traceWarn(...args));
}
loggers.forEach((l) => l.traceWarn(...args));
}

export function traceInfo(...args: Arguments): void {
if (globalLoggingLevel >= LogLevel.Info) {
loggers.forEach((l) => l.traceInfo(...args));
}
loggers.forEach((l) => l.traceInfo(...args));
}

export function traceVerbose(...args: Arguments): void {
if (globalLoggingLevel >= LogLevel.Debug) {
loggers.forEach((l) => l.traceVerbose(...args));
}
loggers.forEach((l) => l.traceVerbose(...args));
}

/** Logging Decorators go here */
Expand All @@ -89,7 +66,7 @@ export function traceDecoratorInfo(message: string): TraceDecoratorType {
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Info });
}
export function traceDecoratorWarn(message: string): TraceDecoratorType {
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Warn });
return createTracingDecorator({ message, opts: DEFAULT_OPTS, level: LogLevel.Warning });
}

// Information about a function/method call.
Expand Down Expand Up @@ -223,7 +200,7 @@ export function logTo(logLevel: LogLevel, ...args: Arguments): void {
case LogLevel.Error:
traceError(...args);
break;
case LogLevel.Warn:
case LogLevel.Warning:
traceWarn(...args);
break;
case LogLevel.Info:
Expand Down
12 changes: 0 additions & 12 deletions src/client/logging/settings.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/client/logging/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-explicit-any */

export type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug';
export type Arguments = unknown[];

export enum LogLevel {
Off = 0,
Error = 10,
Warn = 20,
Info = 30,
Debug = 40,
Trace = 1,
Debug = 2,
Info = 3,
Warning = 4,
Error = 5,
}

export type Arguments = unknown[];

export interface ILogging {
traceLog(...data: Arguments): void;
traceError(...data: Arguments): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createDeferred, Deferred, sleep } from '../../../common/utils/async';
import { createRunningWorkerPool, IWorkerPool, QueuePosition } from '../../../common/utils/workerPool';
import { getInterpreterInfo, InterpreterInformation } from './interpreter';
import { buildPythonExecInfo } from '../../exec';
import { traceError, traceInfo, traceWarn } from '../../../logging';
import { traceError, traceVerbose, traceWarn } from '../../../logging';
import { Conda, CONDA_ACTIVATION_TIMEOUT, isCondaEnvironment } from '../../common/environmentManagers/conda';
import { PythonEnvInfo, PythonEnvKind } from '.';
import { normCasePath } from '../../common/externalDependencies';
Expand Down Expand Up @@ -153,7 +153,7 @@ class EnvironmentInfoService implements IEnvironmentInfoService {
// as complete env info may not be available at this time.
const isCondaEnv = env.kind === PythonEnvKind.Conda || (await isCondaEnvironment(env.executable.filename));
if (isCondaEnv) {
traceInfo(
traceVerbose(
`Validating ${env.executable.filename} normally failed with error, falling back to using conda run: (${reason})`,
);
if (this.condaRunWorkerPool === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/pythonEnvironments/base/info/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
InterpreterInfoJson,
} from '../../../common/process/internal/scripts';
import { Architecture } from '../../../common/utils/platform';
import { traceError, traceInfo } from '../../../logging';
import { traceError, traceVerbose } from '../../../logging';
import { shellExecute } from '../../common/externalDependencies';
import { copyPythonExecInfo, PythonExecInfo } from '../../exec';
import { parseVersion } from './pythonVersion';
Expand Down Expand Up @@ -102,6 +102,6 @@ export async function getInterpreterInfo(
traceError(`Failed to parse interpreter information for >> ${quoted} << with ${ex}`);
return undefined;
}
traceInfo(`Found interpreter for >> ${quoted} <<: ${JSON.stringify(json)}`);
traceVerbose(`Found interpreter for >> ${quoted} <<: ${JSON.stringify(json)}`);
return extractInterpreterInfo(python.pythonExecutable, json);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { Event } from 'vscode';
import { isTestExecution } from '../../../../common/constants';
import { traceInfo, traceVerbose } from '../../../../logging';
import { traceVerbose } from '../../../../logging';
import { arePathsSame, getFileInfo, pathExists } from '../../../common/externalDependencies';
import { PythonEnvInfo, PythonEnvKind } from '../../info';
import { areEnvsDeepEqual, areSameEnv, getEnvPath } from '../../info/env';
Expand Down Expand Up @@ -225,7 +225,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
await this.persistentStorage.store(envs);
return;
}
traceInfo('Environments added to cache', JSON.stringify(this.envs));
traceVerbose('Environments added to cache', JSON.stringify(this.envs));
this.markAllEnvsAsFlushed();
await this.persistentStorage.store(this.envs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createVenvScript } from '../../../common/process/internal/scripts';
import { execObservable } from '../../../common/process/rawProcessApis';
import { createDeferred } from '../../../common/utils/async';
import { Common, CreateEnv } from '../../../common/utils/localize';
import { traceError, traceInfo, traceLog } from '../../../logging';
import { traceError, traceLog, traceVerbose } from '../../../logging';
import { CreateEnvironmentProgress } from '../types';
import { pickWorkspaceFolder } from '../common/workspaceSelection';
import { IInterpreterQuickPick } from '../../../interpreter/configuration/types';
Expand Down Expand Up @@ -208,7 +208,7 @@ export class VenvCreationProvider implements CreateEnvironmentProvider {
throw ex;
}
if (!installInfo) {
traceInfo('Virtual env creation exited during dependencies selection.');
traceVerbose('Virtual env creation exited during dependencies selection.');
return MultiStepAction.Cancel;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/client/pythonEnvironments/creation/provider/venvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CancellationToken, QuickPickItem, RelativePattern, WorkspaceFolder } fr
import { CreateEnv } from '../../../common/utils/localize';
import { MultiStepAction, MultiStepNode, showQuickPickWithBack } from '../../../common/vscodeApis/windowApis';
import { findFiles } from '../../../common/vscodeApis/workspaceApis';
import { traceError, traceInfo, traceVerbose } from '../../../logging';
import { traceError, traceVerbose } from '../../../logging';

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

if (!hasBuildSystem) {
traceInfo('Create env: Found toml without build system. So we will not use editable install.');
traceVerbose('Create env: Found toml without build system. So we will not use editable install.');
}
if (extras.length === 0) {
traceInfo('Create env: Found toml without optional dependencies.');
traceVerbose('Create env: Found toml without optional dependencies.');
}
} else if (context === MultiStepAction.Back) {
// This step is not really used so just go back
Expand Down
4 changes: 2 additions & 2 deletions src/client/pythonEnvironments/info/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function extractInterpreterInfo(python: string, raw: InterpreterInfoJson): Inter
}

type Logger = {
info(msg: string): void;
verbose(msg: string): void;
error(msg: string): void;
};

Expand Down Expand Up @@ -85,7 +85,7 @@ export async function getInterpreterInfo(
}
const json = parse(result.stdout);
if (logger) {
logger.info(`Found interpreter for ${argv}`);
logger.verbose(`Found interpreter for ${argv}`);
}
if (!json) {
return undefined;
Expand Down
Loading