You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Go testing library is the standard unit testing mechanism for the Go universe. The framework's logging mechanism works well for unit tests due to the short, functional nature of the environment, however, it's been adopted in end to end test environments. Long running tests typically have large volumes of logs and can run for tens of minutes which can make it quite difficult to correlate events between systems and reason about logs when parallel testing is involved.
Proposal
Add a mechanism for users to optionally configure a logging header for tests which contains timestamp, test name and other information which may be useful for human log readers.
Alternatives Considered
Require the caller to provide the header
If users need to pass the log header, this will require a fairly large effort to migrate all the callsites in a codebase. This also won't guarantee consistency across all log callsites which will be frustrating for users.
Create a testing like package specifically for large end to end tests
The Go community is very familiar with the existing testing package, it's likely not worth the fragmentation to create another testing package to allow users to add timestamps to logs.
Prior art
Go log package
https://pkg.go.dev/log allows the user to configure a pre-defined logging header through a log.SetPrefix() call. A mechanism like this would be sufficient for resolving the proposal and maintain backward compatibility.
@seankhliao#28544 appears to be resolved by t.Helper() which isn't quite the same as what I'm asking for here. I'd like to be able to emit a timestamp to make long running tests easier to reason about. Emitting a test name would be helpful for parallel testcases where it's easy to be confused about exactly which testcase is running. Are you certain this is a duplicate?
Activity
seankhliao commentedon Mar 29, 2023
Duplicate of #28544
briantkennedy commentedon Mar 29, 2023
@seankhliao #28544 appears to be resolved by
t.Helper()which isn't quite the same as what I'm asking for here. I'd like to be able to emit a timestamp to make long running tests easier to reason about. Emitting a test name would be helpful for parallel testcases where it's easy to be confused about exactly which testcase is running. Are you certain this is a duplicate?seankhliao commentedon Mar 29, 2023
see #36656 for timestamps