Skip to content

Commit 15aaa8c

Browse files
committed
src/goDebugFactory,src/goDebug: only add --log-output flag if --log is set
In order to enable logging, debug users can set "showLog": true and specify the output with "logOutput". These map directly to the delve flags "--log" and "--log-output". If "--log-output" is passed without "--log" delve complains. This means that users always have to remove "--log-output" if they want to disable logging. This change only passes the "--log-output" to delve if "showLog": true. This allows users to disable logging by simply setting "showLog": false. Change-Id: Ic568fbebe6b5ab07b2b5b2e60b6c68659cd67430 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/335029 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 93a6e13 commit 15aaa8c

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/debugAdapter/goDebug.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,11 @@ export class Delve {
639639

640640
if (launchArgs.showLog) {
641641
dlvArgs.push('--log=' + launchArgs.showLog.toString());
642-
}
643-
if (launchArgs.logOutput) {
644-
dlvArgs.push('--log-output=' + launchArgs.logOutput);
642+
// Only add the log output flag if we have already added the log flag.
643+
// Otherwise, delve complains.
644+
if (launchArgs.logOutput) {
645+
dlvArgs.push('--log-output=' + launchArgs.logOutput);
646+
}
645647
}
646648
if (launchArgs.cwd) {
647649
dlvArgs.push('--wd=' + launchArgs.cwd);

src/goDebugFactory.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,11 @@ function spawnDlvDapServerProcess(
379379
dlvArgs.push(`--listen=${host}:${port}`);
380380
if (launchAttachArgs.showLog) {
381381
dlvArgs.push('--log=' + launchAttachArgs.showLog.toString());
382-
}
383-
if (launchAttachArgs.logOutput) {
384-
dlvArgs.push('--log-output=' + launchAttachArgs.logOutput);
382+
// Only add the log output flag if we have already added the log flag.
383+
// Otherwise, delve complains.
384+
if (launchAttachArgs.logOutput) {
385+
dlvArgs.push('--log-output=' + launchAttachArgs.logOutput);
386+
}
385387
}
386388

387389
const onWindows = process.platform === 'win32';

test/integration/goDebug.test.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,22 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
654654
throw new Error('does not report error on invalid delve flag');
655655
});
656656

657+
test('should run program with showLog=false and logOutput specified', async () => {
658+
const PROGRAM = path.join(DATA_ROOT, 'baseTest');
659+
660+
const config = {
661+
name: 'Launch',
662+
type: 'go',
663+
request: 'launch',
664+
mode: 'debug',
665+
program: PROGRAM,
666+
showLog: false,
667+
logOutput: 'dap'
668+
};
669+
const debugConfig = await initializeDebugConfig(config, true);
670+
await Promise.all([dc.configurationSequence(), dc.launch(debugConfig), dc.waitForEvent('terminated')]);
671+
});
672+
657673
test('should handle threads request after initialization', async () => {
658674
const PROGRAM = path.join(DATA_ROOT, 'baseTest');
659675

@@ -2068,13 +2084,15 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
20682084
});
20692085

20702086
let testNumber = 0;
2071-
async function initializeDebugConfig(config: DebugConfiguration) {
2087+
async function initializeDebugConfig(config: DebugConfiguration, keepUserLog?: boolean) {
20722088
if (isDlvDap) {
20732089
config['debugAdapter'] = 'dlv-dap';
2074-
// Log the output for easier test debugging.
2075-
config['logOutput'] = 'dap,debugger';
2076-
config['showLog'] = true;
2077-
config['trace'] = 'verbose';
2090+
if (!keepUserLog) {
2091+
// Log the output for easier test debugging.
2092+
config['logOutput'] = 'dap,debugger';
2093+
config['showLog'] = true;
2094+
config['trace'] = 'verbose';
2095+
}
20782096
} else {
20792097
config['debugAdapter'] = 'legacy';
20802098
// be explicit and prevent resolveDebugConfiguration from picking

0 commit comments

Comments
 (0)