Skip to content

Conversation

@ccoVeille
Copy link
Contributor

This commit introduces an optional logger parameter to various structs.
This enhancement allows users to provide custom logging implementations.

Fixes #3558

Note

This is a follow-up of #3560 that was merged in a branch (not master) and #3618 that was updated by @ndyakov to add changes on it.

The MR is now ready to be merged.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

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

❌ The following Jit checks failed to run:

  • secret-detection-trufflehog
  • static-code-analysis-semgrep-pro

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

@ccoVeille ccoVeille force-pushed the optional-logger branch 3 times, most recently from 93fa6c4 to c963331 Compare November 27, 2025 12:57
@ccoVeille
Copy link
Contributor Author

I apparently failed to keep your GPG signature @ndyakov, it sounds logic as I used history rewritting to fix an issue in one of the commit I did earlier. Feel free to pull, sign your commits, and push again. My fork is now all set for maintainers edits

@ccoVeille ccoVeille mentioned this pull request Nov 27, 2025
@ndyakov ndyakov self-requested a review November 27, 2025 13:54
ndyakov
ndyakov previously approved these changes Nov 27, 2025
Copy link
Member

@ndyakov ndyakov left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, can we just make sure this one is addressed (preferably add a simple test):
#3618 (comment)

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Nov 27, 2025

Overall looks good to me, can we just make sure this one is addressed (preferably add a simple test):
#3618 (comment)

Here the difference I applied to an old commit.

func (cl *LoggerWrapper) Errorf(ctx context.Context, format string, v ...any) { 
         if cl == nil || cl.logger == nil { 
                 legacyLoggerWithLevel.Errorf(ctx, format, v...) 
                 return 
         } 
-         cl.logger.ErrorContext(ctx, format, v...)
+         cl.logger.ErrorContext(cl.printfToStructured(ctx, format, v...))
 }

I can add a test, but adding a test about a logger is never fun.

Maybe it can be done in a separate PR. I'm suggesting that, but if you are OK to wait for me to add the tests a few more days, maybe a week. I can do it.

@ndyakov
Copy link
Member

ndyakov commented Nov 28, 2025

@ccoVeille No problem, I will prepare a beta without the logger, you can write tests and resolve conflicts in the next week and then we will include it.

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Dec 1, 2025

@ndyakov please review again.

I feel the system is better now.

The only thing I'm unsure is the fact the LoggerWrapper should be exported (like in the current PR) or moved to internal/logging

EDIT: this is needed if a LoggerWrapper is provided directly

@ccoVeille
Copy link
Contributor Author

Apparently, I broke something.

It's too late here, but the code is close to what is needed.

@ccoVeille ccoVeille marked this pull request as draft December 2, 2025 08:31
@ccoVeille
Copy link
Contributor Author

I feel like I have to move out the change about fixing the panic and sprintf issue

@ccoVeille
Copy link
Contributor Author

I feel like I have to move out the change about fixing the panic and sprintf issue

Moved to

@ccoVeille
Copy link
Contributor Author

ccoVeille commented Dec 2, 2025

I squashed everything in one commit even yours @ndyakov.

I was done to deal with conflicts when someone was merging something 🙄

@ccoVeille
Copy link
Contributor Author

The PR is still in DRAFT mode because I have no clear status on what is the minimal Go version for go-redis

As stated in #3631, right now the go.mod mentions Go 1.18+, but the current code can only work with Go 1.23+

Except that the code can be reviewed.

But if the minimal version is moved to something at least Go 1.21, my implementation could be simplified a lot as I would be able to delete everything about //go:build tags

ccoVeille and others added 2 commits December 2, 2025 23:32
This commit introduces an optional logger parameter to various structs.
This enhancement allows users to provide custom logging implementations.

An issue will remain for direct calls to internal.Logger.Printf, as the
call depth cannot be adjusted there without changing the function signature.

While most of the changes comes from ccoVeille's work, Nedyalko Dyakov
made some changes in other files to ensure the legacy logger is replaced
with the new logger.

Co-authored-by: Nedyalko Dyakov <[email protected]>
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.

Feature Request: ability to provide a logger as an Options setting

2 participants