Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: testing: allow custom log headers #59311

Closed
briantkennedy opened this issue Mar 29, 2023 · 3 comments
Closed

proposal: testing: allow custom log headers #59311

briantkennedy opened this issue Mar 29, 2023 · 3 comments

Comments

@briantkennedy
Copy link

Problem

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.

Uber Zap Logger

Zap provides a mechanism to customize logging by setting configuration struct members. Of note, setting TimeKey configures the timestamp formatting (or omits it if emtpy)
https://pkg.go.dev/go.uber.org/zap@v1.24.0/zapcore#EncoderConfig

Zerolog

Zerolog allows the user to configure the timestamp in the log header by setting a global variable in the zerolog pacakage.

https://pkg.go.dev/github.com/rs/zerolog#pkg-variables

@gopherbot gopherbot added this to the Proposal milestone Mar 29, 2023
@seankhliao
Copy link
Member

Duplicate of #28544

@seankhliao seankhliao marked this as a duplicate of #28544 Mar 29, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2023
@briantkennedy
Copy link
Author

@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
Copy link
Member

see #36656 for timestamps

@golang golang locked and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants