From: Matt Joiner Date: Thu, 21 Mar 2024 23:51:35 +0000 (+1100) Subject: Some logging improvements X-Git-Tag: v1.56.0~36 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2396e6c618d28b35eabf2d07f5b20dbb754889ed;p=btrtrc.git Some logging improvements --- diff --git a/client.go b/client.go index 23decf6e..90a74d95 100644 --- a/client.go +++ b/client.go @@ -192,7 +192,7 @@ func (cl *Client) initLogger() { logger = log.Default } if cl.config.Debug { - logger = logger.FilterLevel(log.Debug) + logger = logger.WithFilterLevel(log.Debug) } cl.logger = logger.WithValues(cl) } @@ -667,7 +667,7 @@ func DialFirst(ctx context.Context, addr string, dialers []Dialer) (res DialResu func dialFromSocket(ctx context.Context, s Dialer, addr string) net.Conn { c, err := s.Dial(ctx, addr) if err != nil { - log.Levelf(log.Debug, "error dialing %q: %v", addr, err) + log.ContextLogger(ctx).Levelf(log.Debug, "error dialing %q: %v", addr, err) } // This is a bit optimistic, but it looks non-trivial to thread this through the proxy code. Set // it now in case we close the connection forthwith. Note this is also done in the TCP dialer diff --git a/testing.go b/testing.go index 6fb54112..a4909273 100644 --- a/testing.go +++ b/testing.go @@ -20,7 +20,7 @@ func TestingConfig(t testing.TB) *ClientConfig { cfg.ListenPort = 0 cfg.KeepAliveTimeout = time.Millisecond cfg.MinPeerExtensions.SetBit(pp.ExtensionBitFast, true) - cfg.Logger = log.Default.WithContextText(t.Name()) + cfg.Logger = log.Default.WithNames(t.Name()) // 2 would suffice for the greeting test, but 5 is needed for a few other tests. This should be // something slightly higher than the usual chunk size, so it gets tickled in some tests. cfg.MaxAllocPeerRequestDataPerConn = 5