Skip to content

Commit 80a8786

Browse files
authored
Toolkit now updates the logger's logging level when Configuration changes are made (#878)
* Toolkit now updates the logger's logging level when Configuration changes are made (instead of requiring a VS Code restart)
1 parent 2bb0642 commit 80a8786

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "The Toolkit now applies configuration changes to the log level when it changes instead of the next time the toolkit is started (#860)"
4+
}

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function activate(context: vscode.ExtensionContext) {
3838
const localize = nls.loadMessageBundle()
3939

4040
ext.context = context
41-
await activateLogger()
41+
await activateLogger(context)
4242
const toolkitOutputChannel = vscode.window.createOutputChannel(localize('AWS.channel.aws.toolkit', 'AWS Toolkit'))
4343

4444
try {

src/shared/logger/activation.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ const LOG_OUTPUT_CHANNEL: vscode.OutputChannel = vscode.window.createOutputChann
2626
/**
2727
* Activate Logger functionality for the extension.
2828
*/
29-
export async function activate(): Promise<void> {
29+
export async function activate(extensionContext: vscode.ExtensionContext): Promise<void> {
3030
const outputChannel = LOG_OUTPUT_CHANNEL
3131
const logPath = LOG_PATH
3232
const logLevel = getLogLevel()
3333

3434
await ensureLogFolderExists(path.dirname(logPath))
3535

36-
setLogger(makeLogger(logLevel, logPath, outputChannel))
36+
setLogger(makeLogger(logLevel, logPath, outputChannel, extensionContext.subscriptions))
3737

3838
await registerLoggerCommands()
3939

@@ -42,11 +42,27 @@ export async function activate(): Promise<void> {
4242
)
4343
}
4444

45-
export function makeLogger(logLevel: LogLevel, logPath: string, outputChannel: vscode.OutputChannel): Logger {
45+
export function makeLogger(
46+
logLevel: LogLevel,
47+
logPath: string,
48+
outputChannel: vscode.OutputChannel,
49+
disposables?: vscode.Disposable[]
50+
): Logger {
4651
const logger = new WinstonToolkitLogger(logLevel)
4752
logger.logToFile(logPath)
4853
logger.logToOutputChannel(outputChannel)
4954

55+
vscode.workspace.onDidChangeConfiguration(
56+
configurationChangeEvent => {
57+
if (configurationChangeEvent.affectsConfiguration('aws.logLevel')) {
58+
const newLogLevel = vscode.workspace.getConfiguration('aws').get('logLevel', logLevel)
59+
logger.setLogLevel(newLogLevel)
60+
}
61+
},
62+
undefined,
63+
disposables
64+
)
65+
5066
return logger
5167
}
5268

src/shared/logger/winstonToolkitLogger.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ export class WinstonToolkitLogger implements Logger, vscode.Disposable {
4646
}
4747

4848
public setLogLevel(logLevel: LogLevel) {
49-
this.logger.info(`Setting log level to: ${logLevel}`)
49+
// Log calls are made with explicit levels to ensure the text is output
50+
this.logger.log(this.logger.level, `Setting log level to: ${logLevel}`)
5051
this.logger.level = logLevel
52+
this.logger.log(this.logger.level, `Log level is now: ${this.logger.level}`)
5153
}
5254

5355
public logToFile(logPath: string): void {

0 commit comments

Comments
 (0)