Skip to content

various: pass logger.Logf through to more places #7539

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

Merged
merged 1 commit into from
Mar 12, 2023
Merged

Conversation

andrew-d
Copy link
Member

Updates #7537

Change-Id: Id89acab70ea678c8c7ff0f44792d54c7223337c6

@andrew-d andrew-d requested review from maisem and dsnet March 12, 2023 15:02
@@ -382,18 +383,27 @@ func (a *Dialer) dialURL(ctx context.Context, u *url.URL, addr netip.Addr) (*Cli
func (a *Dialer) tryURLUpgrade(ctx context.Context, u *url.URL, addr netip.Addr, init []byte) (net.Conn, error) {
var dns *dnscache.Resolver

// Maintain prior behaviour where passing no logger to
Copy link
Member

Choose a reason for hiding this comment

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

logf method instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I intentionally didn't use that; the a.logf method will drop logs if no a.Logf option is specified, whereas the previous behaviour of dnscache.Resolver always logs with log.Printf if there's no logger specified.

Copy link
Member

Choose a reason for hiding this comment

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

logfOrDefault method then? I just don't want to see a big comment and var decl/conditional in the middle of unrelated code

Copy link
Member Author

@andrew-d andrew-d Mar 12, 2023

Choose a reason for hiding this comment

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

I actually just changed this to use a.Logf directly when constructing the Resolver; this propagates nil-ness and retains the default "fall back to log.Printf" behaviour that dnscache.Resolver has. PTAL?

func SetLogger(log logger.Logf) {
logfunc.Store(log)
// SetLogger sets the logging function that this package will use, and returns
// the old value (which may be nil). The default logger if this function is not
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value of the logger is log.Printf

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, but the default value of the logfunc is nil; the top-level logf function will fall back to log.Printf if so.

Copy link
Contributor

Choose a reason for hiding this comment

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

The value defaults to log.Printf if not explicitly set?

Updates #7537

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: Id89acab70ea678c8c7ff0f44792d54c7223337c6
@andrew-d andrew-d merged commit 83fa17d into main Mar 12, 2023
@andrew-d andrew-d deleted the andrew/more-logf branch March 12, 2023 16:38
mihaip added a commit that referenced this pull request Apr 17, 2023
Redoes the approach from #5550 and #7539 to explicitly pass in the logf
function, instead of having global state that can be overidden.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
mihaip added a commit that referenced this pull request Apr 17, 2023
Redoes the approach from #5550 and #7539 to explicitly pass in the logf
function, instead of having global state that can be overridden.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
mihaip added a commit that referenced this pull request Apr 17, 2023
Redoes the approach from #5550 and #7539 to explicitly pass in the logf
function, instead of having global state that can be overridden.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
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.

3 participants