Repository navigation
Closed as not planned
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
What version of Go are you using (go version)?
$ go version go version go1.13.6 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/vimalkum/.cache/go-build" GOENV="/home/vimalkum/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/vimalkum/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build339334134=/tmp/go-build -gno-record-gcc-switches"
What did you do?
https://play.golang.org/p/525R1YDp8sB
Write a test case which calls t.Log or t.Logf
The output of these logs is generated when a test fails. If i am using a CI for testing, it makes my job much easier if i can correlate test log timestamps with other logs captured by CI
What did you expect to see?
The t.Log statements should produce timestamps.
What did you see instead?
No timestamps
2020/01/20 21:15:05 GetValue called
--- FAIL: TestGetValue (0.00s)
main_test.go:9: this is log statement
main_test.go:11: this is error log statement
main_test.go:12: expected 100
FAIL
exit status 1
FAIL github.com/vimalk78/test-testing 0.001s
Reacted by Ben Moss, Feng Xiong, Jeroen Demeyer, Sankar சங்கர், Vincent Bernat, Karl Isenberg, Pavel Beschetnov, Gergo Huszty, Johan Andersson, Chao and 11 more
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Activity
ianlancetaylor commentedon Jan 21, 2020
I don't think this is what most people want. You can add timestamps yourself to your
t.Logcalls if you want them.TomerYakir commentedon Apr 6, 2021
for what it's worth, I think it'd be a useful feature as well, for the same reason @vimalk78 provided.
It'd be cool if we had a
t.SetPrefixfunction (similarly to how thelogpackage implemented this)maansaake commentedon Sep 14, 2021
Agree, have always used timestamps and would rather not have a separate log package/include a TS snippet in each log statement.
mvdan commentedon Dec 1, 2022
I personally think this would be nice by default; most of the output from
go testalready includes relative timestamps, like how long a test ran for, or how long the entire package took to test. Here's an example of how relative timestamps on logs could look like:cmd/go's TestScript does something similar; each section of a test script has a comment, and the output includes how long that section took to run (cc @bcmills):
When I write long tests in Go, such as integration tests, I often want similar timestamps or durations to be able to tell what's taking most of the time. It's also useful with
go test -v -run OneTest, so that the logs being streamed out can give a better idea of how the time is being spent.Like @ianlancetaylor says, I can always add timestamps or elapsed durations to log calls myself, though at this point I've done that in a handful of different places, and I don't see a reason why we shouldn't do it by default :) I reckon I would generally find this useful for any test which takes more than a tens of milliseconds and prints a few logs.
Worth noting that, with
go test -json, log lines get printed as "output" actions with a timestamp, but that's not very friendly for humans.mvdan commentedon Dec 1, 2022
For the record, my current workaround is:
The logs with
go test -vshow up like:bcmills commentedon Dec 6, 2022
For what it's worth, I added absolute timestamps to
cmd/goscript tests in CL 405714.However, I only added a timestamp at the start of the run: the timestamp at the start combined with the running time of the test give a bounded window in which the events of the test occurred, which was all I really cared about for the purpose (diagnosing test failures caused by errors in non-hermetic external services).
seankhliao commentedon Dec 3, 2024
I think #59928 with the writer passed to a logger would be a better fit
seankhliao commentedon Dec 7, 2025
Use a logger with t.Output if you need timestamps.