vscode-go
vscode-go copied to clipboard
Output of t.Log is not displayed while debugging
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
- Run
go versionto get version of Go from the VS Code integrated terminal.go version go1.24.4 linux/amd64
- Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.18.1
golang.org/x/tools/[email protected] h1:2xJBNzdImS5u/kV/ZzqDLSvlBSeZX+pWY9uKVP7Pask=
github.com/BurntSushi/[email protected] h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0=
golang.org/x/[email protected] h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/[email protected] h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/[email protected] h1:L2k9GUV2TpQKVRGMjN94qfUMgUwOFimSQ6gipyJIjKw=
golang.org/x/[email protected] h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/[email protected] h1:Ja/5gV5a9Vvho3p2NC/T2TtxhHjrWS/2DvCKMvA0a+Y=
golang.org/x/[email protected] h1:NPGnvPOTgnjBc9HTaUx+nj+EaUYxl5SJOWqaDYGaFYw=
honnef.co/go/[email protected] h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
mvdan.cc/[email protected] h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.24.0
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.
Running in Cursor:
Version: 1.0.0
VSCode Version: 1.96.2
Commit: 53b99ce608cba35127ae3a050c1738a959750860
Date: 2025-06-04T19:26:40.367Z
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Linux x64 6.14.9-300.fc42.x86_64
I also tried with vanilla VS code:
Version: 1.100.3
Commit: 258e40fedc6cb8edf399a463ce3a9d32e7e1f6f3
Date: 2025-06-02T13:30:54.273Z
Electron: 34.5.1
ElectronBuildId: 11369351
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Linux x64 6.14.9-300.fc42.x86_64
- Check your installed extensions to get the version of the VS Code Go extension
0.46.1
- Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand.
# Tools Configuration
## Environment
GOBIN: undefined
toolsGopath:
gopath: /home/martin/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/home/martin/.local/bin:/tmp/.mount_CursorDq5tA5/usr/bin/:/tmp/.mount_CursorDq5tA5/usr/sbin/:/tmp/.mount_CursorDq5tA5/usr/games/:/tmp/.mount_CursorDq5tA5/bin/:/tmp/.mount_CursorDq5tA5/sbin/:/home/martin/.local/bin:/usr/local/bin:/usr/bin:<REDACTED>:/home/martin/go/bin:<REDACTED>:/home/martin/go/bin:<REDACTED>
PATH (vscode launched with): /home/martin/.local/bin:/tmp/.mount_CursorDq5tA5/usr/bin/:/tmp/.mount_CursorDq5tA5/usr/sbin/:/tmp/.mount_CursorDq5tA5/usr/games/:/tmp/.mount_CursorDq5tA5/bin/:/tmp/.mount_CursorDq5tA5/sbin/:/home/martin/.local/bin:/usr/local/bin:/usr/bin:/usr/local/go/bin:<REDACTED>:/home/martin/go/bin:<REDACTED>
## Tools
go: /usr/local/go/bin/go: go version go1.24.4 linux/amd64
gopls: /home/martin/go/bin/gopls (version: v0.18.1 built with go: go1.24.0)
gotests: not installed
gomodifytags: not installed
impl: /home/martin/go/bin/impl (version: v1.4.0 built with go: go1.24.3)
goplay: not installed
dlv: /home/martin/go/bin/dlv (version: v1.24.1 built with go: go1.24.2)
staticcheck: /home/martin/go/bin/staticcheck (version: v0.6.1 built with go: go1.24.0)
## Go env
Workspace Folder (vscode-go-debug-test-output): /home/martin/Projects/vscode-go-debug-test-output
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/martin/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/martin/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1075938469=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/martin/Projects/vscode-go-debug-test-output/go.mod'
GOMODCACHE='/home/martin/go/pkg/mod'
GONOPROXY='<REDACTED>'
GONOSUMDB='<REDACTED>/*'
GOOS='linux'
GOPATH='/home/martin/go'
GOPRIVATE='<REDACTED>'
GOPROXY='<REDACTED>'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/martin/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK=''
PKG_CONFIG='pkg-config'
Share the Go related settings you have added/edited
Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.
"go.goroot": "/usr/local/go",
Describe the bug
When I debug a test that logs output using t.Log, the log output is not visible anywhere until the test finishes.
Example test:
func TestMy(t *testing.T) {
t.Log("some output " + time.Now().String())
time.Sleep(1000) // breakpoint here
t.Fail()
}
I expected to see t.Log output during debugging of the test while I set a breakpoint on the line with the sleep in the example. But the test output is not visible anywhere.
In my case the real test outputs connection information for connecting to the database instance started for the test case using testcontainers-go.
I tried adding
{
"go.testFlags": [
"-v"
]
}
to project's settings.json, but this did not help.
Also the Test Results tab show the result of the previous test run, which is confusing.
Steps to reproduce the behavior:
- Go to the Go file with the test
- Add a breakpoint after
t.Log()call - Click on
Debug testin the line above the test function in the code editor - Run the program until the breakpoint
- Look for the output of
t.Log()from the debug session, but it is not visible anywhere. The output is visible only after the test finishes.
Seems that workaround is to install prerelease vscode-go and Go Companion.
Output should work as expected for the old code lenses and test explorer. I'm glad you found a workaround but this is an issue. Did you launch the debug session using the testing panel, the gutter play button, or the "debug test" code lens?
Did you launch the debug session using the testing panel, the gutter play button, or the "debug test" code lens?
Initially I was using only the "debug test" code lens, but I just tried all three and the behavior is the same. See screencasts:
In all three cases the output is shown only after the test finishes.
Great. @firelizzard18 looks like this is already being captured by the Go Companion mode.
Do you think we can include this as part of the Go Companion effort?
Ultimately the issue is that launching a test in debug mode doesn't respect the test flags, so the debug executable is launched without -v. I got caught up thinking I was testing the same thing as @martin-sucha and wondering how this could work, but when I checked the actual args that are passed to delve, the only flag that's passed is -run (technically -test.run).
@h9jiang Do you mean, "Consider this fixed by Go Companion and defer the fix until that is merged into vscode-go?" That depends on whether you're ok with leaving this unfixed until then. That being said, IMO we should solve "Output is not displayed while debugging" by adding -test.v to getTestFunctionDebugArgs since that's an easy fix. As far as the larger issue (debug mode doesn't respect test flags), maybe it is time to work on merging Go Companion's test explorer. Excluding issues that require updates to go or gopls, there are are only four unfinished Go Companion tasks and two of those boil down to updating or removing legacy commands. I do need to add more comments and tests but I haven't made a substantial change since December (excluding the go:generate stuff since I wasn't planning on merging that). There are some pieces that lack polish/feel a bit unfinished like the profiling and coverage configuration, but they're good enough, fairly isolated, and I don't know how to make them feel better.