Skip to content

Commit 2c0661c

Browse files
authored
Remove src/client/logging/* from .eslintignore (microsoft#17178)
* Remove non-existent files * Clean up src/client/logging/* * Re-add comment * News file
1 parent 41d075c commit 2c0661c

15 files changed

Lines changed: 224 additions & 184 deletions

File tree

.eslintignore

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ src/test/language/tokenizer.unit.test.ts
9696
src/test/api.functional.test.ts
9797

9898
src/test/testing/mocks.ts
99-
src/test/testing/helper.ts
10099
src/test/testing/common/debugLauncher.unit.test.ts
101-
src/test/testing/common/testUtils.unit.test.ts
102-
src/test/testing/common/services/storageService.unit.test.ts
103100
src/test/testing/common/services/configSettingService.unit.test.ts
104-
src/test/testing/results.ts
105101

106102
src/test/common/exitCIAfterTestReporter.ts
107103
src/test/common/crypto.unit.test.ts
@@ -495,15 +491,6 @@ src/client/application/diagnostics/commands/factory.ts
495491
src/client/application/diagnostics/commands/execVSCCommand.ts
496492
src/client/application/diagnostics/commands/launchBrowser.ts
497493

498-
src/client/logging/levels.ts
499-
src/client/logging/transports.ts
500-
src/client/logging/_global.ts
501-
src/client/logging/logger.ts
502-
src/client/logging/util.ts
503-
src/client/logging/index.ts
504-
src/client/logging/formatters.ts
505-
src/client/logging/trace.ts
506-
507494
src/client/refactor/proxy.ts
508495
src/client/workspaceSymbols/main.ts
509496
src/client/workspaceSymbols/generator.ts

news/3 Code Health/17181.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix linting for some files in .eslintignore.

src/client/common/utils/decorators.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ export type CallInfo = {
219219
args: any[];
220220
};
221221

222+
export type TraceDecoratorType = (
223+
_: Object,
224+
__: string,
225+
descriptor: TypedPropertyDescriptor<any>,
226+
) => TypedPropertyDescriptor<any>;
227+
222228
// Return a decorator that traces the decorated function.
223-
export function trace(log: (c: CallInfo, t: TraceInfo) => void) {
229+
export function trace(log: (c: CallInfo, t: TraceInfo) => void): TraceDecoratorType {
224230
return function (_: Object, __: string, descriptor: TypedPropertyDescriptor<any>) {
225231
const originalMethod = descriptor.value;
226232

src/client/logging/_global.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

56
import * as winston from 'winston';
@@ -8,7 +9,7 @@ import { CallInfo } from '../common/utils/decorators';
89
import { getFormatter } from './formatters';
910
import { LogLevel, resolveLevelName } from './levels';
1011
import { configureLogger, createLogger, getPreDefinedConfiguration, logToAll } from './logger';
11-
import { createTracingDecorator, LogInfo, TraceOptions, tracing as _tracing } from './trace';
12+
import { LogInfo, tracing as _tracing } from './trace';
1213
import { getPythonOutputChannelTransport, IPythonOutputChannelContent } from './transports';
1314
import { Arguments } from './util';
1415

@@ -44,7 +45,7 @@ function initialize() {
4445
}
4546

4647
// Set the logging level the extension logs at.
47-
export function setLoggingLevel(level: LogLevel | 'off') {
48+
export function setLoggingLevel(level: LogLevel | 'off'): void {
4849
if (level === 'off') {
4950
// For now we disable all logging. One alternative would be
5051
// to only disable logging to the output channel (by removing
@@ -59,7 +60,7 @@ export function setLoggingLevel(level: LogLevel | 'off') {
5960
}
6061

6162
// Register the output channel transport the logger will log into.
62-
export function addOutputChannelLogging(channel: IOutputChannel) {
63+
export function addOutputChannelLogging(channel: IOutputChannel): void {
6364
const formatter = getFormatter();
6465
const transport = getPythonOutputChannelTransport(channel, formatter);
6566
_globalLoggerContent = transport;
@@ -75,19 +76,19 @@ function log(logLevel: LogLevel, ...args: Arguments) {
7576
logToAll([globalLogger], logLevel, args);
7677
}
7778

78-
export function logVerbose(...args: any[]) {
79+
export function logVerbose(...args: Arguments): void {
7980
log(LogLevel.Info, ...args);
8081
}
8182

82-
export function logError(...args: any[]) {
83+
export function logError(...args: Arguments): void {
8384
log(LogLevel.Error, ...args);
8485
}
8586

86-
export function logInfo(...args: any[]) {
87+
export function logInfo(...args: Arguments): void {
8788
log(LogLevel.Info, ...args);
8889
}
8990

90-
export function logWarning(...args: any[]) {
91+
export function logWarning(...args: Arguments): void {
9192
log(LogLevel.Warn, ...args);
9293
}
9394

@@ -96,24 +97,6 @@ export function tracing<T>(info: LogInfo, run: () => T, call?: CallInfo): T {
9697
return _tracing([globalLogger], info, run, call);
9798
}
9899

99-
export namespace traceDecorators {
100-
const DEFAULT_OPTS: TraceOptions = TraceOptions.Arguments | TraceOptions.ReturnValue;
101-
102-
export function verbose(message: string, opts: TraceOptions = DEFAULT_OPTS) {
103-
return createTracingDecorator([globalLogger], { message, opts });
104-
}
105-
export function error(message: string) {
106-
const opts = DEFAULT_OPTS;
107-
const level = LogLevel.Error;
108-
return createTracingDecorator([globalLogger], { message, opts, level });
109-
}
110-
export function info(message: string) {
111-
const opts = TraceOptions.None;
112-
return createTracingDecorator([globalLogger], { message, opts });
113-
}
114-
export function warn(message: string) {
115-
const opts = DEFAULT_OPTS;
116-
const level = LogLevel.Warn;
117-
return createTracingDecorator([globalLogger], { message, opts, level });
118-
}
100+
export function getGlobalLogger(): winston.Logger {
101+
return globalLogger;
119102
}

src/client/logging/formatters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

6+
import { Format } from 'logform';
57
import { format } from 'winston';
68
import { isTestExecution } from '../common/constants';
79
import { getLevel, LogLevel, LogLevelName } from './levels';
@@ -78,7 +80,7 @@ function getLabeledFormatter(label_: string) {
7880
}
7981

8082
// Return a format object that can be used with a "winston" logging transport.
81-
export function getFormatter(opts: FormatterOptions = {}) {
83+
export function getFormatter(opts: FormatterOptions = {}): Format {
8284
if (opts.label) {
8385
return getLabeledFormatter(opts.label);
8486
}

src/client/logging/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

56
export {
@@ -12,5 +13,6 @@ export {
1213
logVerbose,
1314
logWarning,
1415
getPythonOutputChannelContent,
15-
traceDecorators,
1616
} from './_global';
17+
18+
export * as traceDecorators from './traceDecorators';

src/client/logging/levels.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

56
// IMPORTANT: This file should only be importing from the '../client/logging' directory, as we
67
// delete everything in '../client' except for '../client/logging' before running smoke tests.
78

89
import * as winston from 'winston';
910

10-
//======================
1111
// Our custom log levels
1212

1313
export enum LogLevel {
@@ -35,7 +35,6 @@ const configLevels: winston.config.AbstractConfigSetLevels = {
3535
'DEBUG-TRACE': 5,
3636
};
3737

38-
//======================
3938
// Other log levels
4039

4140
// The level names from winston/config.npm.
@@ -49,8 +48,7 @@ const npmLogLevelMap: { [K in LogLevel]: NPMLogLevelName } = {
4948
[LogLevel.Trace]: 'silly',
5049
};
5150

52-
//======================
53-
// lookup functions
51+
// Lookup functions
5452

5553
// Convert from LogLevel enum to the proper level name.
5654
export function resolveLevelName(
@@ -60,13 +58,14 @@ export function resolveLevelName(
6058
): string | undefined {
6159
if (levels === undefined) {
6260
return getLevelName(level);
63-
} else if (levels === configLevels) {
61+
}
62+
if (levels === configLevels) {
6463
return getLevelName(level);
65-
} else if (levels === winston.config.npm.levels) {
64+
}
65+
if (levels === winston.config.npm.levels) {
6666
return npmLogLevelMap[level];
67-
} else {
68-
return undefined;
6967
}
68+
return undefined;
7069
}
7170
function getLevelName(level: LogLevel): LogLevelName | undefined {
7271
return logLevelMap[level];
@@ -89,10 +88,7 @@ export function resolveLevel(
8988
return undefined;
9089
}
9190
for (const level of Object.keys(levelMap)) {
92-
if (typeof level === 'string') {
93-
continue;
94-
}
95-
if (logLevelMap[level] === levelName) {
91+
if (typeof level !== 'string' && logLevelMap[level] === levelName) {
9692
return level;
9793
}
9894
}

src/client/logging/logger.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

56
// IMPORTANT: This file should only be importing from the '../client/logging' directory, as we
@@ -24,7 +25,7 @@ type LoggerConfig = {
2425
};
2526

2627
// Create a logger just the way we like it.
27-
export function createLogger(config?: LoggerConfig) {
28+
export function createLogger(config?: LoggerConfig): winston.Logger {
2829
const logger = winston.createLogger({
2930
// We would also set "levels" here.
3031
exitOnError: false, // Do not exit extension host if there is an exception.
@@ -68,7 +69,7 @@ export function getPreDefinedConfiguration(): LoggerConfig {
6869
}
6970

7071
// Set up a logger just the way we like it.
71-
export function configureLogger(logger: IConfigurableLogger, config: LoggerConfig) {
72+
export function configureLogger(logger: IConfigurableLogger, config: LoggerConfig): void {
7273
if (config.level) {
7374
const levelName = resolveLevelName(config.level);
7475
if (levelName) {
@@ -95,7 +96,7 @@ export interface ILogger {
9596
}
9697

9798
// Emit a log message derived from the args to all enabled transports.
98-
export function logToAll(loggers: ILogger[], logLevel: LogLevel, args: Arguments) {
99+
export function logToAll(loggers: ILogger[], logLevel: LogLevel, args: Arguments): void {
99100
const message = args.length === 0 ? '' : util.format(args[0], ...args.slice(1));
100101
for (const logger of loggers) {
101102
if (logger.transports.length > 0) {
@@ -118,10 +119,10 @@ function getLevelName(level: LogLevel, levels: winston.config.AbstractConfigSetL
118119
const levelName = resolveLevelName(level, levels);
119120
if (levelName) {
120121
return levelName;
121-
} else if (isConsole) {
122+
}
123+
if (isConsole) {
122124
// XXX Hard-coding this is fragile:
123125
return 'silly';
124-
} else {
125-
return resolveLevelName(LogLevel.Info, levels) || 'info';
126126
}
127+
return resolveLevelName(LogLevel.Info, levels) || 'info';
127128
}

src/client/logging/trace.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
34
'use strict';
45

5-
import { CallInfo, trace as traceDecorator } from '../common/utils/decorators';
6+
import { CallInfo, trace as traceDecorator, TraceDecoratorType } from '../common/utils/decorators';
67
import { TraceInfo, tracing as _tracing } from '../common/utils/misc';
78
import { sendTelemetryEvent } from '../telemetry';
9+
import { EventName } from '../telemetry/constants';
810
import { LogLevel } from './levels';
911
import { ILogger, logToAll } from './logger';
1012
import { argsToLogString, returnValueToLogString } from './util';
@@ -16,7 +18,7 @@ export enum TraceOptions {
1618
ReturnValue = 2,
1719
}
1820

19-
export function createTracingDecorator(loggers: ILogger[], logInfo: LogInfo) {
21+
export function createTracingDecorator(loggers: ILogger[], logInfo: LogInfo): TraceDecoratorType {
2022
return traceDecorator((call, traced) => logResult(loggers, logInfo, traced, call));
2123
}
2224

@@ -72,6 +74,6 @@ function logResult(loggers: ILogger[], info: LogInfo, traced: TraceInfo, call?:
7274
} else {
7375
logToAll(loggers, LogLevel.Error, [formatted, traced.err]);
7476

75-
sendTelemetryEvent('ERROR' as any, undefined, undefined, traced.err);
77+
sendTelemetryEvent(('ERROR' as unknown) as EventName, undefined, undefined, traced.err);
7678
}
7779
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { TraceDecoratorType } from '../common/utils/decorators';
2+
import { LogLevel } from './levels';
3+
import { createTracingDecorator, TraceOptions } from './trace';
4+
import { getGlobalLogger } from './_global';
5+
6+
const DEFAULT_OPTS: TraceOptions = TraceOptions.Arguments | TraceOptions.ReturnValue;
7+
8+
export function verbose(message: string, opts: TraceOptions = DEFAULT_OPTS): TraceDecoratorType {
9+
const globalLogger = getGlobalLogger();
10+
return createTracingDecorator([globalLogger], { message, opts });
11+
}
12+
export function error(message: string): TraceDecoratorType {
13+
const opts = DEFAULT_OPTS;
14+
const level = LogLevel.Error;
15+
const globalLogger = getGlobalLogger();
16+
return createTracingDecorator([globalLogger], { message, opts, level });
17+
}
18+
export function info(message: string): TraceDecoratorType {
19+
const opts = TraceOptions.None;
20+
const globalLogger = getGlobalLogger();
21+
return createTracingDecorator([globalLogger], { message, opts });
22+
}
23+
export function warn(message: string): TraceDecoratorType {
24+
const opts = DEFAULT_OPTS;
25+
const level = LogLevel.Warn;
26+
const globalLogger = getGlobalLogger();
27+
return createTracingDecorator([globalLogger], { message, opts, level });
28+
}

0 commit comments

Comments
 (0)