Skip to content

Conversation

@strowk
Copy link

@strowk strowk commented Oct 30, 2025

When tests do not fail, what they printed rarely matters. However, when they do fail, it is important to see maximum information. This change switches default behavior back as was in 0.31, when failures could be quickly triaged without adding -v

label: fix, qol

What does this PR do?

Simply switches default logging behavior to more convenient one in realworld scenarios.

Why is it important?

Test output matters when we need to read it, we read it when tests fail, otherwise we might not even care if they run (if it is some pipeline).

Related issues

How to test this PR

#2887 (comment)

Ideally maybe it should buffer logs and print them out only when failure happened. This could affect memory usage though, so IMO defaulting to complete output would be preferred behavior in majority of the cases.

@strowk strowk requested a review from a team as a code owner October 30, 2025 18:38
@netlify
Copy link

netlify bot commented Oct 30, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit e73e10e
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6903d56010a1dd00089d99da
😎 Deploy Preview https://deploy-preview-3459--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 project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Summary by CodeRabbit

  • Chores
    • Updated logging initialization to write to standard error output by default.
    • Modified logging behavior during testing to ensure cleaner test output.

Walkthrough

Logger initialization in log/logger.go was changed to create a real stderr logger by default and to explicitly disable logging only when the -test.v=false flag is present, replacing the previous no-op default and the prior flag-inspection behavior.

Changes

Cohort / File(s) Summary
Logger Initialization
log/logger.go
Replaced defaultLogger no-op with a real stderr logger using standard flags; updated Init logic to disable logging only when -test.v=false is found; clarified comments around testing/verbose flag handling.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant LoggerPkg as log/logger.go
    participant Stderr

    App->>LoggerPkg: call Init()
    LoggerPkg->>LoggerPkg: inspect os.Args for "-test.v=false"
    alt "-test.v=false" present
        LoggerPkg->>LoggerPkg: set defaultLogger = noopLogger
    else
        LoggerPkg->>Stderr: create real logger (stderr, std flags)
        LoggerPkg->>LoggerPkg: set defaultLogger = real logger
    end
    LoggerPkg-->>App: Init complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Single-file change but affects runtime behavior during tests and normal runs.
  • Areas to check:
    • Correct parsing/handling of os.Args edge cases (multiple flags, ordering).
    • No unintended log noise on stderr in non-test environments.
    • Tests or CI that depend on previous no-op behavior.

Poem

🐰 I peeped at flags beneath the moonlit view,
I swapped my silence for a sturdy hue.
To stderr now my tiny hooves impart,
Container whispers—logs to mend your heart. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix: should print max information by default" directly relates to the main change in the pull request. The raw_summary indicates that the defaultLogger initialization was changed from a no-op logger to a real logger that writes to stderr, which enables printing information by default. The title is clear, concise, and specific enough to convey the primary change without excessive detail.
Linked Issues Check ✅ Passed The code changes align with the primary objective from linked issue #2887, which requests restoring the behavior where container logs are printed when a container exits so failures can be properly troubleshooted. The PR changes the defaultLogger initialization from a no-op logger to a real logger that writes to stderr using standard flags, which directly addresses the regression where container logs were no longer being printed by default. This change restores the logging behavior to an earlier, more verbose state that was present in v0.31.
Out of Scope Changes Check ✅ Passed All code changes in this pull request are directly within scope and related to the stated objectives from linked issue #2887. The modifications to log/logger.go focus on changing the defaultLogger initialization and updating the testing mode logic, both of which are necessary to implement the primary goal of restoring default logging behavior to print container logs when containers exit. No changes appear to introduce functionality unrelated to fixing the missing container logs regression.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@strowk strowk force-pushed the fix_default_logger branch 2 times, most recently from 0140132 to c66c912 Compare October 30, 2025 18:40
When tests do not fail, what they printed rarely
matters. However, when they do fail, it is important
to see maximum information. This change switches
default behavior back as was in 0.31, when failures
could be quickly triaged without adding -v
@strowk strowk force-pushed the fix_default_logger branch from c66c912 to 320b05e Compare October 30, 2025 18:41
@strowk strowk changed the title should print max information by default fix: should print max information by default Oct 30, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9895e2e and 320b05e.

📒 Files selected for processing (1)
  • log/logger.go (1 hunks)
🔇 Additional comments (2)
log/logger.go (2)

22-23: LGTM! Default logging behavior restored.

This change successfully restores the default logging to stderr, which addresses the regression described in #2887. The use of log.LstdFlags provides helpful timestamp context for log entries.


28-34: Fix typo in comment and confirm manual verification with issue #2887.

The logic is correct and safe—the flag check only runs during test initialization and only affects test mode. However:

  1. Fix the typo on line 28: "Disble" → "Disable"
  2. Verify this resolves the regression by testing with the instructions at #2887 (comment)

The change is well-scoped (init-time only, test-mode only) and won't affect other scenarios; 16+ existing usages of log.Default() across the codebase remain compatible.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
log/logger.go (1)

28-28: Consider removing redundant comment.

The comment on line 28 repeats the information already stated in line 26. Since we're inside the testing.Testing() block, the context is already clear.

-		// Disable logging if explicitly disabled via -test.v=false
 		for _, arg := range os.Args {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 320b05e and e73e10e.

📒 Files selected for processing (1)
  • log/logger.go (1 hunks)
🔇 Additional comments (2)
log/logger.go (2)

22-23: LGTM! Restores verbose logging by default.

The change from a no-op logger to an active stderr logger aligns perfectly with the PR objective to restore v0.31 behavior and addresses issue #2887 where container logs were missing on failures.


29-34: LGTM! Flag parsing logic is correct.

The implementation correctly checks for -test.v=false format, which is the only valid way to explicitly set the boolean test.v flag to false in Go. The logic appropriately disables logging only when this flag is explicitly present.

@mdelapenya mdelapenya self-assigned this Nov 3, 2025
@mdelapenya mdelapenya added the bug An issue with the library label Nov 3, 2025
@mdelapenya
Copy link
Member

Hi @strowk I asked in #1984 about feedback, although I understand what you described in the issue and PR. This is key to me:

Test output matters when we need to read it, we read it when tests fail,

I'm fine in merging the changes proposed in this PR, I just want some alignment in the community about it.

for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
if strings.EqualFold(arg, "-test.v=false") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Create a public constructor for the noopLogger, or remove it and use log.New(io.Discard, "", 0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strowk what are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue with the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression]: Missing container logs when container exited

3 participants