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

[Enhancement]: Reduce verbose log output #1984

Closed
mfridman opened this issue Dec 7, 2023 · 7 comments · Fixed by #2624
Closed

[Enhancement]: Reduce verbose log output #1984

mfridman opened this issue Dec 7, 2023 · 7 comments · Fixed by #2624
Assignees
Labels
enhancement New feature or request

Comments

@mfridman
Copy link

mfridman commented Dec 7, 2023

Proposal

The default log output from this package is quite verbose. It would be ideal if the happy path (by default) logged as little as possible and reported only errors. And for those that do want verbose output, there could be a "verbose" flag or setting that could be enabled.

TL;DR - regardless if it's opt-in or opt-out, it'd be nice for this to be configurable.


  1. I explicitly disabled this feature, no need for this output:
**********************************************************************************************
Ryuk has been disabled for the current execution. This can cause unexpected behavior in your environment.
More on this: https://golang.testcontainers.org/features/garbage_collector/
**********************************************************************************************
  1. Not really interested in the Docker engine info:
2023/12/06 21:56:59 github.com/testcontainers/testcontainers-go - Connected to docker: 
  Server Version: 24.0.6
  API Version: 1.43
  Operating System: Docker Desktop
  Total Memory: 7944 MB
  Resolved Docker Host: unix:///var/run/docker.sock
  Resolved Docker Socket Path: /var/run/docker.sock
  Test SessionID: be5bcf090d5ac5b55046d7a35a670ab7341c71919218f6ee1e64ea4190322e69
  Test ProcessID: 469ede8f-9797-46fb-9ce8-eccb642a0d47
  1. This is cute (hehe), but not strictly necessary:
2023/12/06 21:50:06 🐳 Creating container for image postgres:16-alpine
2023/12/06 21:50:06 ✅ Container created: f40dcefbd017
2023/12/06 21:50:06 🐳 Starting container: f40dcefbd017
2023/12/06 21:50:07 ✅ Container started: f40dcefbd017
2023/12/06 21:50:07 🚧 Waiting for container id f40dcefbd017 image: postgres:16-alpine. Waiting for: &{timeout:<nil> deadline:0xc0001a6e98 Strategies:[0xc0003b1a40]}

[...]

2023/12/06 22:15:03 🐳 Terminating container: f40dcefbd017
2023/12/06 22:15:03 🚫 Container terminated: f40dcefbd017

I added a custom logger, but it only suppressed items 2 and 3 above.

type nopLogger struct{}

var _ testcontainers.Logging = nopLogger{}

func (nopLogger) Printf(string, ...interface{}) {}
@mfridman mfridman added the enhancement New feature or request label Dec 7, 2023
@ntin90
Copy link

ntin90 commented Jan 17, 2024

I work around by setting the global Logger of tescontainers to ioutils.NopWriter, as following:

testcontainers.Logger = log.New(&ioutils.NopWriter{}, "", 0)

However it is not documented in official doc and is not straightforward to figure it out. It's still worth to implement its own NopLogger.

@mfridman
Copy link
Author

This only partially suppresses the output, there's still a "Ryuk has been disabled [...]" message that is a straight fmt print call:

fmt.Println(ryukDisabledMessage)

@ar-sematell
Copy link

ar-sematell commented Jun 10, 2024

There are a lot of places calling internal "log" as well.
It needs reference of the Logger variable to other packages such as "wait"
wait/host_port.go:139

I can open a PR if the devs want it

@mdelapenya
Copy link
Collaborator

mdelapenya commented Jun 12, 2024

Hi folks, I'm tackling this issue as part of the revamp for an eventual v1 release candidate for the library (please see https://github.com/testcontainers/testcontainers-go/tree/v1)

I like the idea of only adding the default logging hook if and only if the -v flag is passed. Apart from that, the idea is to create one single place for the library logger, so that it's possible to configure it once in the client code.

Regarding the Ryuk banner, we encourage its usage, so we'd like to keep it as soon as it's not intrusive.

@mdelapenya mdelapenya self-assigned this Jun 12, 2024
@webstradev
Copy link

webstradev commented Jun 28, 2024

I think it would be quite nice to reduce the amount of logs.

When I run my test suite and I want to see the actual failure message I have to scroll through a bunch of testcontainer status logs.
Would be nice if all of this is only there if you run with -v or something like that.
image

@mdelapenya
Copy link
Collaborator

Hi folks, I submitted #2624, PLMK what you think.

Thanks!

@mfridman
Copy link
Author

mfridman commented Jul 5, 2024

Thanks @mdelapenya, I'll give this a shot in some OSS projects I maintain over the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants