src/debugAdapter: accept additional trace levels
The purpose of this PR is to match the allowed 'trace' attribute values
acceptable by the legacy and the new dlv-dap modes. The old debug
adapter simply maps 'trace' to 'verbose', and 'info' and 'warn' to
'log'.
Add add 'warn' level support to `src/goLogging.ts`.
Updated dlv-dap.md
Change-Id: I0a5836e255a6b576258879e84d63b862b397f1e3
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/311809
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/docs/dlv-dap.md b/docs/dlv-dap.md
index 7a4d91f..6a4aeb8 100644
--- a/docs/dlv-dap.md
+++ b/docs/dlv-dap.md
@@ -106,7 +106,7 @@
}
```
-Set `logOutput` and `showLog` attributes in `launch.json` to enable logging and DAP message tracing.
+Set `logOutput` and `showLog` attributes in `launch.json` to enable `dlv'-side logging and DAP message tracing.
```json5
{
"name": "Launch file",
@@ -118,6 +118,19 @@
}
```
+Set `trace` attribute to control the verbosity of debug extension's logging.
+The logging will appear in the `Go Debug` output channel (Command Palette -> "View: Toggle Output" -> Select "Go Debug" from the dropdown menu).
+
+```json5
+{
+ "name": "Launch file",
+ "type": "go",
+ "debugAdapter": "dlv-dap",
+ "trace": "verbose",
+ ...
+}
+```
+
If you are having issues with seeing logs and or suspect problems in extension's integration, you can start Delve DAP server from a separate terminal and configure the extension to directly connect to it.
```
diff --git a/package.json b/package.json
index 0fae713..4a28cde 100644
--- a/package.json
+++ b/package.json
@@ -616,12 +616,15 @@
"trace": {
"type": "string",
"enum": [
- "log",
"verbose",
+ "trace",
+ "log",
+ "info",
+ "warn",
"error"
],
"default": "error",
- "description": "Various levels of logging shown in the debug console. When set to 'log' or 'verbose', the logs will also be written to a file."
+ "description": "Various levels of the debug console & 'Go Debug' output channel. When using the `legacy` debug adapter, the logs will also be written to a file if it is set to a value other than `error`."
},
"envFile": {
"type": [
diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts
index 515e0a0..882b522 100644
--- a/src/debugAdapter/goDebug.ts
+++ b/src/debugAdapter/goDebug.ts
@@ -281,7 +281,12 @@
host?: string;
buildFlags?: string;
init?: string;
- trace?: 'verbose' | 'log' | 'error';
+ // trace, info, warn are to match goLogging.
+ // In practice, this adapter handles only verbose, log, and error
+ // verbose === trace,
+ // log === info === warn,
+ // error
+ trace?: 'verbose' | 'trace' | 'info' | 'log' | 'warn' | 'error';
backend?: string;
output?: string;
substitutePath?: { from: string; to: string }[];
@@ -315,7 +320,7 @@
remotePath?: string;
port?: number;
host?: string;
- trace?: 'verbose' | 'log' | 'error';
+ trace?: 'verbose' | 'trace' | 'info' | 'log' | 'warn' | 'error';
backend?: string;
substitutePath?: { from: string; to: string }[];
/** Delve LoadConfig parameters */
@@ -1954,9 +1959,9 @@
args: LaunchRequestArguments | AttachRequestArguments
) {
this.logLevel =
- args.trace === 'verbose'
+ args.trace === 'verbose' || args.trace === 'trace'
? Logger.LogLevel.Verbose
- : args.trace === 'log'
+ : args.trace === 'log' || args.trace === 'info' || args.trace === 'warn'
? Logger.LogLevel.Log
: Logger.LogLevel.Error;
const logPath =
diff --git a/src/goLogging.ts b/src/goLogging.ts
index cb36201..fb1bc9e 100644
--- a/src/goLogging.ts
+++ b/src/goLogging.ts
@@ -5,21 +5,23 @@
'use strict';
-type LogLevel = 'off' | 'error' | 'info' | 'trace' | 'verbose';
+type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'trace' | 'verbose';
const levels: { [key in LogLevel]: number } = {
off: -1,
error: 0,
- info: 1,
- trace: 2,
- verbose: 3
+ warn: 1,
+ info: 2,
+ trace: 3,
+ verbose: 4
};
-// TODO: consider 'warning' level.
function levelToString(level: number) {
switch (level) {
case levels.error:
return 'Error';
+ case levels.warn:
+ return 'Warn';
case levels.info:
return 'Info';
case levels.trace:
@@ -55,6 +57,9 @@
error(msg: string) {
this.log(levels.error, msg);
}
+ warn(msg: string) {
+ this.log(levels.warn, msg);
+ }
info(msg: string) {
this.log(levels.info, msg);
}
@@ -91,14 +96,22 @@
defaultLogger = new Logger(cfg.level);
}
-export function logVerbose(msg: string) {
- defaultLogger?.debug(msg);
-}
-
export function logError(msg: string) {
defaultLogger?.error(msg);
}
+export function logWarn(msg: string) {
+ defaultLogger?.warn(msg);
+}
+
export function logInfo(msg: string) {
defaultLogger?.info(msg);
}
+
+export function logTrace(msg: string) {
+ defaultLogger?.trace(msg);
+}
+
+export function logVerbose(msg: string) {
+ defaultLogger?.debug(msg);
+}
diff --git a/test/unit/logger.test.ts b/test/unit/logger.test.ts
index 0efd15e..1cbc970 100644
--- a/test/unit/logger.test.ts
+++ b/test/unit/logger.test.ts
@@ -22,6 +22,7 @@
const appendLine = sandbox.fake();
const logger = new Logger(level, { appendLine });
logger.error('error');
+ logger.warn('warn');
logger.info('info');
logger.debug('debug');
logger.trace('trace');
@@ -29,9 +30,10 @@
}
test('logger level = off', () => runTest('off', 0));
test('logger level = error', () => runTest('error', 1));
- test('logger level = info', () => runTest('info', 2));
- test('logger level = trace', () => runTest('trace', 3));
- test('logger level = verbose', () => runTest('verbose', 4));
+ test('logger level = warning', () => runTest('warn', 2));
+ test('logger level = info', () => runTest('info', 3));
+ test('logger level = trace', () => runTest('trace', 4));
+ test('logger level = verbose', () => runTest('verbose', 5));
test('logger level = undefined', () => runTest(undefined, 1));
test('logger level = ""', () => runTest('', 1));
test('logger level = object', () => runTest({}, 1));