Add trackID to logger context (#375)

This commit is contained in:
Raja Subramanian
2022-01-26 13:23:38 +05:30
committed by GitHub
parent 44afa8bae1
commit 45b07e2b3f
4 changed files with 11 additions and 5 deletions

View File

@@ -165,8 +165,7 @@ func (t *MediaTrack) getNumUpTracks() (uint32, uint32) {
func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, twcc *twcc.Responder) {
buff, rtcpReader := t.params.BufferFactory.GetBufferPair(uint32(track.SSRC()))
if buff == nil || rtcpReader == nil {
logger.Errorw("could not retrieve buffer pair", nil,
"track", t.ID())
t.params.Logger.Errorw("could not retrieve buffer pair", nil)
return
}
buff.OnFeedback(t.handlePublisherFeedback)

View File

@@ -215,7 +215,6 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, code
return
}
t.params.Logger.Debugw("removing peerconnection track",
"track", t.params.MediaTrack.ID(),
"subscriber", sub.Identity(),
"subscriberID", subscriberID,
"kind", t.params.MediaTrack.Kind(),
@@ -270,7 +269,7 @@ func (t *MediaTrackSubscriptions) RemoveSubscriber(participantID livekit.Partici
}
func (t *MediaTrackSubscriptions) RemoveAllSubscribers() {
t.params.Logger.Debugw("removing all subscribers", "track", t.params.MediaTrack.ID())
t.params.Logger.Debugw("removing all subscribers")
t.subscribedTracksMu.Lock()
subscribedTracks := t.subscribedTracks

View File

@@ -1383,7 +1383,7 @@ func (p *ParticipantImpl) mediaTrackReceived(track *webrtc.TrackRemote, rtpRecei
ReceiverConfig: p.params.Config.Receiver,
AudioConfig: p.params.AudioConfig,
Telemetry: p.params.Telemetry,
Logger: p.params.Logger,
Logger: LoggerWithTrack(p.params.Logger, livekit.TrackID(ti.Sid)),
SubscriberConfig: p.params.Config.Subscriber,
})

View File

@@ -154,3 +154,11 @@ func LoggerWithRoom(l logger.Logger, name livekit.RoomName, roomID livekit.RoomI
}
return logger.Logger(lr)
}
func LoggerWithTrack(l logger.Logger, trackID livekit.TrackID) logger.Logger {
lr := logr.Logger(l)
if trackID != "" {
lr = lr.WithValues("trackID", trackID)
}
return logger.Logger(lr)
}