]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Some logging improvements
authorMatt Joiner <anacrolix@gmail.com>
Thu, 21 Mar 2024 23:51:35 +0000 (10:51 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 21 Mar 2024 23:51:35 +0000 (10:51 +1100)
client.go
testing.go

index 23decf6ee0b23341b07861ff997370c2c5abb4a8..90a74d9570a7183fa0fcc3f9dba3a9931261dfce 100644 (file)
--- 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
index 6fb5411267e8c486d454ba384d823f59e9ccc6bd..a49092730814fa8632f8db3c2f3c0caa083b2b32 100644 (file)
@@ -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