Skip to content

Commit 4a3f0e0

Browse files
authored
feat(amazonq): enable show logs (#7733)
## Problem We needed a solution to 1 click access the logs on the disk. ## Solution Implemented a button for it. And also wired the related language server changes for this. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 2fb0926 commit 4a3f0e0

File tree

5 files changed

+50
-468
lines changed

5 files changed

+50
-468
lines changed

packages/amazonq/src/extension.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import { registerCommands } from './commands'
4545
import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat'
4646
import { activate as activateAmazonqLsp } from './lsp/activation'
4747
import { hasGlibcPatch } from './lsp/client'
48-
import { RotatingLogChannel } from './lsp/rotatingLogChannel'
4948

5049
export const amazonQContextPrefix = 'amazonq'
5150

@@ -104,12 +103,7 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
104103
globals.manifestPaths.endpoints = context.asAbsolutePath(join('resources', 'endpoints.json'))
105104
globals.regionProvider = RegionProvider.fromEndpointsProvider(makeEndpointsProvider())
106105

107-
// Create rotating log channel for all Amazon Q logs
108-
const qLogChannel = new RotatingLogChannel(
109-
'Amazon Q Logs',
110-
context,
111-
vscode.window.createOutputChannel('Amazon Q Logs', { log: true })
112-
)
106+
const qLogChannel = vscode.window.createOutputChannel('Amazon Q Logs', { log: true })
113107
await activateLogger(context, amazonQContextPrefix, qLogChannel)
114108
globals.logOutputChannel = qLogChannel
115109
globals.loginManager = new LoginManager(globals.awsContext, new CredentialsStore())
@@ -118,8 +112,6 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
118112
getLogger().error('fs.init: invalid env vars found: %O', homeDirLogs)
119113
}
120114

121-
getLogger().info('Rotating logger has been setup')
122-
123115
await activateTelemetry(context, globals.awsContext, Settings.instance, 'Amazon Q For VS Code')
124116

125117
await initializeAuth(globals.loginManager)

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ import {
8181
SecurityIssueTreeViewProvider,
8282
CodeWhispererConstants,
8383
} from 'aws-core-vscode/codewhisperer'
84-
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl, isTextEditor } from 'aws-core-vscode/shared'
84+
import {
85+
amazonQDiffScheme,
86+
AmazonQPromptSettings,
87+
messages,
88+
openUrl,
89+
isTextEditor,
90+
globals,
91+
} from 'aws-core-vscode/shared'
8592
import {
8693
DefaultAmazonQAppInitContext,
8794
messageDispatcher,
@@ -429,6 +436,38 @@ export function registerMessageListeners(
429436
case listMcpServersRequestType.method:
430437
case mcpServerClickRequestType.method:
431438
case tabBarActionRequestType.method:
439+
// handling for show_logs button
440+
if (message.params.action === 'show_logs') {
441+
languageClient.info('[VSCode Client] Received show_logs action, showing disclaimer')
442+
443+
// Show warning message without buttons - just informational
444+
void vscode.window.showWarningMessage(
445+
'Log files may contain sensitive information such as account IDs, resource names, and other data. Be careful when sharing these logs.'
446+
)
447+
448+
// Get the log directory path
449+
const logPath = globals.context.logUri?.fsPath
450+
const result = { ...message.params, success: false }
451+
452+
if (logPath) {
453+
// Open the log directory in the OS file explorer directly
454+
languageClient.info('[VSCode Client] Opening logs directory')
455+
await vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(logPath))
456+
result.success = true
457+
} else {
458+
// Fallback: show error if log path is not available
459+
void vscode.window.showErrorMessage('Log location not available.')
460+
languageClient.error('[VSCode Client] Log location not available')
461+
}
462+
463+
void webview?.postMessage({
464+
command: message.command,
465+
params: result,
466+
})
467+
468+
break
469+
}
470+
// eslint-disable-next-line no-fallthrough
432471
case listAvailableModelsRequestType.method:
433472
await resolveChatResponse(message.command, message.params, languageClient, webview)
434473
break

packages/amazonq/src/lsp/client.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as nls from 'vscode-nls'
88
import { LanguageClient, LanguageClientOptions, RequestType, State } from 'vscode-languageclient'
99
import { InlineCompletionManager } from '../app/inline/completion'
1010
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
11-
import { RotatingLogChannel } from './rotatingLogChannel'
1211
import {
1312
CreateFilesParams,
1413
DeleteFilesParams,
@@ -95,23 +94,6 @@ export async function startLanguageServer(
9594

9695
const clientId = 'amazonq'
9796
const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`)
98-
99-
// Create custom output channel that writes to disk but sends UI output to the appropriate channel
100-
const lspLogChannel = new RotatingLogChannel(
101-
traceServerEnabled ? 'Amazon Q Language Server' : 'Amazon Q Logs',
102-
extensionContext,
103-
traceServerEnabled
104-
? vscode.window.createOutputChannel('Amazon Q Language Server', { log: true })
105-
: globals.logOutputChannel
106-
)
107-
108-
// Add cleanup for our file output channel
109-
toDispose.push({
110-
dispose: () => {
111-
lspLogChannel.dispose()
112-
},
113-
})
114-
11597
let executable: string[] = []
11698
// apply the GLIBC 2.28 path to node js runtime binary
11799
if (isSageMaker()) {
@@ -191,6 +173,7 @@ export async function startLanguageServer(
191173
window: {
192174
notifications: true,
193175
showSaveFileDialog: true,
176+
showLogs: true,
194177
},
195178
textDocument: {
196179
inlineCompletionWithReferences: {
@@ -209,9 +192,15 @@ export async function startLanguageServer(
209192
},
210193
},
211194
/**
212-
* Using our RotatingLogger for all logs
195+
* When the trace server is enabled it outputs a ton of log messages so:
196+
* When trace server is enabled, logs go to a seperate "Amazon Q Language Server" output.
197+
* Otherwise, logs go to the regular "Amazon Q Logs" channel.
213198
*/
214-
outputChannel: lspLogChannel,
199+
...(traceServerEnabled
200+
? {}
201+
: {
202+
outputChannel: globals.logOutputChannel,
203+
}),
215204
}
216205

217206
const client = new LanguageClient(

packages/amazonq/src/lsp/rotatingLogChannel.ts

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

0 commit comments

Comments
 (0)