1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-17 04:29:52 +08:00
Files
kubo/routing/dht/dht_logger.go
Juan Batiz-Benet 972c0f7b4b u.DOut -> log.Debug
and other logging switches. I kept the u.PErr and u.POut in cli
commands, as those do need to write raw output directly.
2014-10-09 04:50:22 -07:00

42 lines
587 B
Go

package dht
import (
"encoding/json"
"time"
)
type logDhtRPC struct {
Type string
Start time.Time
End time.Time
Duration time.Duration
RPCCount int
Success bool
}
func startNewRPC(name string) *logDhtRPC {
r := new(logDhtRPC)
r.Type = name
r.Start = time.Now()
return r
}
func (l *logDhtRPC) EndLog() {
l.End = time.Now()
l.Duration = l.End.Sub(l.Start)
}
func (l *logDhtRPC) Print() {
b, err := json.Marshal(l)
if err != nil {
log.Debug(err.Error())
} else {
log.Debug(string(b))
}
}
func (l *logDhtRPC) EndAndPrint() {
l.EndLog()
l.Print()
}