}
}
-const debugLogValue = log.Debug
-
-func (cl *Client) debugLogFilter(m log.Msg) bool {
- if cl.config.Debug {
- return true
- }
- return !m.HasValue(debugLogValue)
-}
-
func (cl *Client) initLogger() {
- cl.logger = cl.config.Logger.WithValues(cl).WithFilter(cl.debugLogFilter)
+ cl.logger = cl.config.Logger.WithValues(cl)
+ if !cl.config.Debug {
+ cl.logger = cl.logger.FilterLevel(log.Info)
+ }
}
func (cl *Client) announceKey() int32 {
return
}
if err != nil {
- log.Fmsg("error accepting connection: %s", err).AddValue(debugLogValue).Log(cl.logger)
+ log.Fmsg("error accepting connection: %s", err).SetLevel(log.Debug).Log(cl.logger)
continue
}
go func() {
if reject != nil {
torrent.Add("rejected accepted connections", 1)
- log.Fmsg("rejecting accepted conn: %v", reject).AddValue(debugLogValue).Log(cl.logger)
+ log.Fmsg("rejecting accepted conn: %v", reject).SetLevel(log.Debug).Log(cl.logger)
conn.Close()
} else {
go cl.incomingConnection(conn)
l.Addr().Network(),
conn.LocalAddr(),
conn.RemoteAddr(),
- ).AddValue(debugLogValue).Log(cl.logger)
+ ).SetLevel(log.Debug).Log(cl.logger)
torrent.Add(fmt.Sprintf("accepted conn remote IP len=%d", len(addrIpOrNil(conn.RemoteAddr()))), 1)
torrent.Add(fmt.Sprintf("accepted conn network=%s", conn.RemoteAddr().Network()), 1)
torrent.Add(fmt.Sprintf("accepted on %s listener", l.Addr().Network()), 1)
if err != nil {
log.Fmsg(
"error receiving handshakes on %v: %s", c, err,
- ).AddValue(
- debugLogValue,
- ).Add(
- "network", c.network,
- ).Log(cl.logger)
+ ).SetLevel(log.Debug).
+ Add(
+ "network", c.network,
+ ).Log(cl.logger)
torrent.Add("error receiving handshake", 1)
cl.lock()
cl.onBadAccept(c.remoteAddr)
}
if t == nil {
torrent.Add("received handshake for unloaded torrent", 1)
- log.Fmsg("received handshake for unloaded torrent").AddValue(debugLogValue).Log(cl.logger)
+ log.Fmsg("received handshake for unloaded torrent").SetLevel(log.Debug).Log(cl.logger)
cl.lock()
cl.onBadAccept(c.remoteAddr)
cl.unlock()
torrent.Add("completed handshake over ipv6", 1)
}
if err := t.addConnection(c); err != nil {
- log.Fmsg("error adding connection: %s", err).AddValues(c, debugLogValue).Log(t.logger)
+ log.Fmsg("error adding connection: %s", err).AddValues(c).SetLevel(log.Debug).Log(t.logger)
return
}
defer t.dropConnection(c)
network: network,
connString: connString,
}
- c.logger = cl.logger.WithValues(c,
- log.Debug, // I want messages to default to debug, and can set it here as it's only used by new code
- ).WithText(func(m log.Msg) string {
+ c.logger = cl.logger.WithValues(c).WithDefaultLevel(log.Debug).WithText(func(m log.Msg) string {
return fmt.Sprintf("%v: %s", c, m.Text())
})
c.writerCond.L = cl.locker()
github.com/anacrolix/dht/v2 v2.5.1-0.20200317023935-129f05e9b752
github.com/anacrolix/envpprof v1.1.0
github.com/anacrolix/go-libutp v1.0.2
- github.com/anacrolix/log v0.6.0
+ github.com/anacrolix/log v0.6.1-0.20200416071330-f58a030e6149
github.com/anacrolix/missinggo v1.2.1
github.com/anacrolix/missinggo/perf v1.0.0
github.com/anacrolix/missinggo/v2 v2.4.1-0.20200227072623-f02f6484f997
github.com/anacrolix/log v0.5.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
github.com/anacrolix/log v0.6.0 h1:5y+wtTWoecbrAWWuoBCH7UuGFiD6q2jnQxrLK01RC+Q=
github.com/anacrolix/log v0.6.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
+github.com/anacrolix/log v0.6.1-0.20200416071330-f58a030e6149 h1:3cEyLU9ObAfTnBHCev8uuWGhbHfol8uTwyMRkLIpZGg=
+github.com/anacrolix/log v0.6.1-0.20200416071330-f58a030e6149/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+7cn+rWMIphK1gDH2hrDuwGOcbB6V4VXeSsEfHVk=
github.com/anacrolix/missinggo v0.0.0-20180725070939-60ef2fbf63df/go.mod h1:kwGiTUTZ0+p4vAz3VbAI5a30t2YbvemcmspjKwrAz5s=
github.com/anacrolix/missinggo v0.2.1-0.20190310234110-9fbdc9f242a8 h1:E2Xb2SBsVzHJ1tNMW9QcckYEQcyBKz1ee8qVjeVRWys=
})
case pp.Suggest:
torrent.Add("suggests received", 1)
- log.Fmsg("peer suggested piece %d", msg.Index).AddValues(c, msg.Index, debugLogValue).Log(c.t.logger)
+ log.Fmsg("peer suggested piece %d", msg.Index).AddValues(c, msg.Index).SetLevel(log.Debug).Log(c.t.logger)
c.updateRequests()
case pp.HaveAll:
err = c.onPeerSentHaveAll()
delete(c.validReceiveChunks, newRequestFromMessage(&msg))
case pp.AllowedFast:
torrent.Add("allowed fasts received", 1)
- log.Fmsg("peer allowed fast: %d", msg.Index).AddValues(c, debugLogValue).Log(c.t.logger)
+ log.Fmsg("peer allowed fast: %d", msg.Index).AddValues(c).SetLevel(log.Debug).Log(c.t.logger)
c.peerAllowedFast.Add(int(msg.Index))
c.updateRequests()
case pp.Extended:
func (cl *Client) addPortMapping(d upnp.Device, proto upnp.Protocol, internalPort int, upnpID string) {
externalPort, err := d.AddPortMapping(proto, internalPort, internalPort, upnpID, 0)
if err != nil {
- cl.logger.WithValues(log.Warning).Printf("error adding %s port mapping: %s", proto, err)
+ cl.logger.WithDefaultLevel(log.Warning).Printf("error adding %s port mapping: %s", proto, err)
} else if externalPort != internalPort {
- cl.logger.WithValues(log.Warning).Printf("external port %d does not match internal port %d in port mapping", externalPort, internalPort)
+ cl.logger.WithDefaultLevel(log.Warning).Printf("external port %d does not match internal port %d in port mapping", externalPort, internalPort)
} else {
- cl.logger.WithValues(log.Info).Printf("forwarded external %s port %d", proto, externalPort)
+ cl.logger.WithDefaultLevel(log.Info).Printf("forwarded external %s port %d", proto, externalPort)
}
}
t.logger.Printf("marked piece %v complete but still has dirtiers", piece)
}
if changed {
- log.Fstr("piece %d completion changed: %+v -> %+v", piece, cached, uncached).WithValues(debugLogValue).Log(t.logger)
+ log.Fstr("piece %d completion changed: %+v -> %+v", piece, cached, uncached).SetLevel(log.Debug).Log(t.logger)
t.pieceCompletionChanged(piece)
}
return changed
wst := websocketTracker{*u, webtorrent.NewTrackerClient(t.cl.peerID, t.infoHash, t.onWebRtcConn,
t.logger.WithText(func(m log.Msg) string {
return fmt.Sprintf("%q: %v", u.String(), m.Text())
- }).WithValues(log.Debug))}
+ }).WithDefaultLevel(log.Debug))}
ar := t.announceRequest(tracker.Started)
go func() {
err := wst.TrackerClient.Run(ar, u.String())
if err != nil {
- t.logger.WithValues(log.Error).Printf(
+ t.logger.WithDefaultLevel(log.Error).Printf(
"error running websocket tracker announcer for %q: %v",
u.String(), err)
}
defer cl.lock()
err := t.announceToDht(true, s)
if err != nil {
- t.logger.WithValues(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
+ t.logger.WithDefaultLevel(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
}
}()
}
}
func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
- t.logger.Log(log.Fstr("hashed piece %d (passed=%t)", piece, passed).WithValues(debugLogValue))
+ t.logger.Log(log.Fstr("hashed piece %d (passed=%t)", piece, passed).SetLevel(log.Debug))
p := t.piece(piece)
p.numVerifies++
t.cl.event.Broadcast()
me.t.cl.rLock()
req := me.t.announceRequest(event)
me.t.cl.rUnlock()
- me.t.logger.WithValues(log.Debug).Printf("announcing to %q: %#v", me.u.String(), req)
+ me.t.logger.WithDefaultLevel(log.Debug).Printf("announcing to %q: %#v", me.u.String(), req)
res, err := tracker.Announce{
HTTPProxy: me.t.cl.config.HTTPProxy,
UserAgent: me.t.cl.config.HTTPUserAgent,
return fmt.Errorf("failed to dial tracker: %w", err)
}
defer t.Close()
- c.logger.WithValues(log.Info).Printf("dialed tracker %q", url)
+ c.logger.WithDefaultLevel(log.Debug).Printf("dialed tracker %q", url)
c.tracker = t
go func() {
err := c.announce(ar)
if err != nil {
- c.logger.WithValues(log.Error).Printf("error announcing: %v", err)
+ c.logger.WithDefaultLevel(log.Error).Printf("error announcing: %v", err)
}
}()
return c.trackerReadLoop()
if err != nil {
return fmt.Errorf("read error: %w", err)
}
- c.logger.WithValues(log.Debug).Printf("received message from tracker: %q", message)
+ c.logger.WithDefaultLevel(log.Debug).Printf("received message from tracker: %q", message)
var ar AnnounceResponse
if err := json.Unmarshal(message, &ar); err != nil {
offer, ok := c.outboundOffers[ar.OfferID]
c.lock.Unlock()
if !ok {
- c.logger.WithValues(log.Warning).Printf("could not find offer for id %q", ar.OfferID)
+ c.logger.WithDefaultLevel(log.Warning).Printf("could not find offer for id %q", ar.OfferID)
continue
}
c.logger.Printf("offer %q got answer %v", ar.OfferID, *ar.Answer)