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

Enable implicit default logger only in testing with -v #2877

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

apstndb
Copy link

@apstndb apstndb commented Nov 6, 2024

What does this PR do?

This PR changes -v and -test.v=true handling only takes effect if testing.Testing() = true, i.e. go test.

Why is it important?

The current implementation always treats -v and -test.v=true specially, even outside of go test, and outputs verbose logs that are not easy to suppress. This makes it difficult to use testcontainers outside of go test.

Related issues

How to test this PR

These behaviors should not be changed.

$ go test
$ go test -v
$ go test -test.v=true

These behavior will be changed to suppress default logging.

$ go run ./ -v

@apstndb apstndb requested a review from a team as a code owner November 6, 2024 10:08
Copy link

netlify bot commented Nov 6, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit a9fbef9
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/672b410bbe58800008652a73
😎 Deploy Preview https://deploy-preview-2877--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@apstndb apstndb changed the title Enable default logger only in testing Enable default logger only in testing with -v Nov 6, 2024
@mdelapenya
Copy link
Member

@apstndb thanks for opening the issue and working on the fix. I have one question about your use case: What do you expect when go run -v is executed?

From what I can see with the implementation in this PR, for the use case above of executing go run -v, we are going to always suppress the logging. I'd expect the -v flag enables the logging.

Could you share more on your use case so we can understand better the needs behind it? 🙏

@apstndb
Copy link
Author

apstndb commented Nov 6, 2024

My expectation is that go run ./(or binary built by go build) won't generally follow go test convention.

  • It won't know -test.v=true.
  • It can use --verbose or -vv for vebose mode, and it can even use -v for other purpose.

It means the current behavior of enforcing go test convention to go run ./ is not good.

In this case, users can implement their own handling by explicitly setting testcontainers.Logger = logger or testcontainers.WithLogger(logger). It is not hard.

@apstndb apstndb changed the title Enable default logger only in testing with -v Enable implicit default logger only in testing with -v Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: -v enable logs which is not intuitive to control
2 participants