]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Tweak logging
authorMatt Joiner <anacrolix@gmail.com>
Thu, 18 May 2023 11:25:44 +0000 (21:25 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 18 May 2023 11:25:58 +0000 (21:25 +1000)
client.go
go.mod
go.sum
main_test.go
testing.go
torrent.go
ut-holepunching_test.go

index 70b98482820e1bd488c161383c176c02dd3f14d4..7d2523f97fb431a4994eb79ed725aa8cec23c698 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1294,7 +1294,7 @@ func (cl *Client) newTorrentOpt(opts AddTorrentOpts) (t *Torrent) {
        t.smartBanCache.Hash = sha1.Sum
        t.smartBanCache.Init()
        t.networkingEnabled.Set()
-       t.logger = cl.logger.WithContextValue(t).WithNames("torrent", t.infoHash.HexString()).WithDefaultLevel(log.Debug)
+       t.logger = cl.logger.WithDefaultLevel(log.Debug)
        t.sourcesLogger = t.logger.WithNames("sources")
        if opts.ChunkSize == 0 {
                opts.ChunkSize = defaultChunkSize
@@ -1601,8 +1601,8 @@ func (cl *Client) newConnection(nc net.Conn, opts newConnectionOpts) (c *PeerCon
        }
        c.logger.Levelf(
                log.Debug,
-               "new PeerConn %p [Client %p remoteAddr %v network %v outgoing %t]",
-               c, cl, opts.remoteAddr, opts.network, opts.outgoing,
+               "inited with remoteAddr %v network %v outgoing %t",
+               opts.remoteAddr, opts.network, opts.outgoing,
        )
        for _, f := range cl.config.Callbacks.NewPeer {
                f(&c.Peer)
diff --git a/go.mod b/go.mod
index 80c9f34ae1a02cc0f7f5ce9c62eac519d7ae742e..1e5973f09f0bf85ffbfd9176f93c9bab9bfa72be 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
        github.com/anacrolix/fuse v0.2.0
        github.com/anacrolix/generics v0.0.0-20230428105757-683593396d68
        github.com/anacrolix/go-libutp v1.2.0
-       github.com/anacrolix/log v0.13.2-0.20221123232138-02e2764801c3
+       github.com/anacrolix/log v0.13.2-0.20230518105052-6aef2c4c91f1
        github.com/anacrolix/missinggo v1.3.0
        github.com/anacrolix/missinggo/perf v1.0.0
        github.com/anacrolix/missinggo/v2 v2.7.0
diff --git a/go.sum b/go.sum
index 3dbd985b1a5f13c3f7eaa81335de002af2514320..65810afdaf42cccf23e84e657d8e27daad674bc6 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -84,8 +84,8 @@ github.com/anacrolix/log v0.3.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgw
 github.com/anacrolix/log v0.6.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
 github.com/anacrolix/log v0.10.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
 github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8/go.mod h1:GmnE2c0nvz8pOIPUSC9Rawgefy1sDXqposC2wgtBZE4=
-github.com/anacrolix/log v0.13.2-0.20221123232138-02e2764801c3 h1:qDcPnH18SanNZMeMuEjzKpB3NQGR1ahytV08KOhZhNo=
-github.com/anacrolix/log v0.13.2-0.20221123232138-02e2764801c3/go.mod h1:MD4fn2pYcyhUAQg9SxoGOpTnV/VIdiKVYKZdCbDC97k=
+github.com/anacrolix/log v0.13.2-0.20230518105052-6aef2c4c91f1 h1:Yo4XQhmdmrkB4RGP7RWvl8U+og2rCBsNqoJFTew0plk=
+github.com/anacrolix/log v0.13.2-0.20230518105052-6aef2c4c91f1/go.mod h1:1OmJESOtxQGNMlUO5rcv96Vpp9mfMqXXbe2RdinFLdY=
 github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62 h1:P04VG6Td13FHMgS5ZBcJX23NPC/fiC4cp9bXwYujdYM=
 github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62/go.mod h1:66cFKPCO7Sl4vbFnAaSq7e4OXtdMhRSBagJGWgmpJbM=
 github.com/anacrolix/missinggo v0.0.0-20180725070939-60ef2fbf63df/go.mod h1:kwGiTUTZ0+p4vAz3VbAI5a30t2YbvemcmspjKwrAz5s=
index 51af26a041374468d11efece53c88b61999942e4..578d992178d744a4d892bd692f7114a13a8477c4 100644 (file)
@@ -6,10 +6,12 @@ import (
        "testing"
 
        _ "github.com/anacrolix/envpprof"
+       analog "github.com/anacrolix/log"
 )
 
 func init() {
        log.SetFlags(log.LstdFlags | log.Lshortfile)
+       analog.DefaultTimeFormatter = analog.TimeFormatSecondsSinceInit
 }
 
 func TestMain(m *testing.M) {
index 1df8abc0d34b09333906c142e3aecc7586eada1e..d3f04b669e8c679da3df629b2bdb7294d4661afc 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.WithNames(t.Name())
+       cfg.Logger = log.Default.WithContextText(t.Name())
        //cfg.Debug = true
        //cfg.Logger = cfg.Logger.WithText(func(m log.Msg) string {
        //      t := m.Text()
index 553fa5db25e8bdf98e0e39f1f52a13254f48650b..5184fc795971f6aa3987db55f51ce37ab439ab53 100644 (file)
@@ -1071,7 +1071,7 @@ func (t *Torrent) maybeDropMutuallyCompletePeer(
        if p.useful() {
                return
        }
-       t.logger.WithDefaultLevel(log.Debug).Printf("dropping %v, which is mutually complete", p)
+       p.logger.Levelf(log.Debug, "is mutually complete; dropping")
        p.drop()
 }
 
index 18521195cec547999f9e09fc436a714ceb6bceb1..ba3d6ad8c21b37bf66529a02f866912d8ede2af6 100644 (file)
@@ -43,6 +43,7 @@ func TestHolepunchConnect(t *testing.T) {
        // Ensure that responding to holepunch connects don't wait around for the dial limit. We also
        // have to allow the initial connection to the leecher though, so it can rendezvous for us.
        cfg.DialRateLimiter = rate.NewLimiter(0, 1)
+       cfg.Logger = cfg.Logger.WithContextText("seeder")
        seeder, err := NewClient(cfg)
        require.NoError(t, err)
        defer seeder.Close()
@@ -56,10 +57,11 @@ func TestHolepunchConnect(t *testing.T) {
        cfg.Seed = true
        cfg.DataDir = t.TempDir()
        cfg.AlwaysWantConns = true
+       cfg.Logger = cfg.Logger.WithContextText("leecher")
        // This way the leecher leecher will still try to use this peer as a relay, but won't be told
        // about the seeder via PEX.
        //cfg.DisablePEX = true
-       //cfg.Debug = true
+       cfg.Debug = true
        leecher, err := NewClient(cfg)
        require.NoError(t, err)
        defer leecher.Close()
@@ -69,8 +71,9 @@ func TestHolepunchConnect(t *testing.T) {
        cfg.Seed = false
        cfg.DataDir = t.TempDir()
        cfg.MaxAllocPeerRequestDataPerConn = 4
-       //cfg.Debug = true
+       cfg.Debug = true
        cfg.NominalDialTimeout = time.Second
+       cfg.Logger = cfg.Logger.WithContextText("leecher-leecher")
        //cfg.DisableUTP = true
        leecherLeecher, _ := NewClient(cfg)
        require.NoError(t, err)