From bfb77899967e52bc004e981220e792759e1c3e05 Mon Sep 17 00:00:00 2001 From: Nonoo Date: Sun, 18 Oct 2020 11:17:40 +0200 Subject: [PATCH] Use stream name in common logging --- audiostream.go | 2 +- controlstream.go | 2 +- streamcommon.go | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/audiostream.go b/audiostream.go index 02832c1..61ba298 100644 --- a/audiostream.go +++ b/audiostream.go @@ -11,7 +11,7 @@ type audioStream struct { } func (s *audioStream) Start() { - s.common.open(50003) + s.common.open("audio", 50003) s.common.sendPkt3() diff --git a/controlstream.go b/controlstream.go index eabfec8..c2ae5f3 100644 --- a/controlstream.go +++ b/controlstream.go @@ -236,7 +236,7 @@ func (s *controlStream) handleRead(r []byte) { } func (s *controlStream) Start() { - s.common.open(50001) + s.common.open("control", 50001) s.common.sendPkt3() s.common.sendSeq = 1 diff --git a/streamcommon.go b/streamcommon.go index f416dce..c096c87 100644 --- a/streamcommon.go +++ b/streamcommon.go @@ -10,6 +10,7 @@ import ( ) type streamCommon struct { + name string conn *net.UDPConn localSID uint32 remoteSID uint32 @@ -46,9 +47,9 @@ func (s *streamCommon) reader(c chan []byte) { } else { errCount++ if errCount > 5 { - log.Fatal("timeout") + log.Fatal(s.name + "/timeout") } - log.Error("stream break detected") + log.Error(s.name + "/stream break detected") } errCount = 0 } @@ -69,9 +70,10 @@ func (s *streamCommon) expect(packetLength int, b []byte) []byte { return r } -func (s *streamCommon) open(portNumber int) { +func (s *streamCommon) open(name string, portNumber int) { + s.name = name hostPort := fmt.Sprint(connectAddress, ":", portNumber) - log.Print("connecting to ", hostPort) + log.Print(s.name+"/connecting to ", hostPort) raddr, err := net.ResolveUDPAddr("udp", hostPort) if err != nil { log.Fatal(err) @@ -85,7 +87,7 @@ func (s *streamCommon) open(portNumber int) { } s.localSID = uint32(time.Now().Unix()) - log.Debugf("using session id %.8x", s.localSID) + log.Debugf(s.name+"/using session id %.8x", s.localSID) } func (p *streamCommon) sendPkt3() {