Refactor logging into separate package
This commit is contained in:
18
mc/beacon.go
18
mc/beacon.go
@@ -52,17 +52,17 @@ func (b *Beacon) reader() {
|
||||
for {
|
||||
n, addr, err := b.conn.ReadFrom(bs)
|
||||
if err != nil {
|
||||
dlog.Println(err)
|
||||
l.Warnln("Beacon read:", err)
|
||||
return
|
||||
}
|
||||
if debug {
|
||||
dlog.Printf("recv %d bytes from %s", n, addr)
|
||||
l.Debugf("recv %d bytes from %s", n, addr)
|
||||
}
|
||||
select {
|
||||
case b.outbox <- recv{bs[:n], addr}:
|
||||
default:
|
||||
if debug {
|
||||
dlog.Println("Dropping message")
|
||||
l.Debugln("dropping message")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (b *Beacon) writer() {
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
dlog.Println(err)
|
||||
l.Warnln("Beacon: interface addresses:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -90,16 +90,22 @@ func (b *Beacon) writer() {
|
||||
dsts = append(dsts, net.IP{0xff, 0xff, 0xff, 0xff})
|
||||
}
|
||||
|
||||
if debug {
|
||||
l.Debugln("addresses:", dsts)
|
||||
}
|
||||
|
||||
for _, ip := range dsts {
|
||||
dst := &net.UDPAddr{IP: ip, Port: b.port}
|
||||
|
||||
_, err := b.conn.WriteTo(bs, dst)
|
||||
if err != nil {
|
||||
dlog.Println(err)
|
||||
if debug {
|
||||
l.Debugln(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if debug {
|
||||
dlog.Printf("sent %d bytes to %s", len(bs), dst)
|
||||
l.Debugf("sent %d bytes to %s", len(bs), dst)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package mc
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/calmh/syncthing/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
dlog = log.New(os.Stderr, "mc: ", log.Lmicroseconds|log.Lshortfile)
|
||||
debug = strings.Contains(os.Getenv("STTRACE"), "mc")
|
||||
debug = strings.Contains(os.Getenv("STTRACE"), "mc") || os.Getenv("STTRACE") == "all"
|
||||
l = logger.DefaultLogger
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user