Add roomID to logger util (#345)
This commit is contained in:
+7
-4
@@ -60,7 +60,7 @@ type ParticipantOptions struct {
|
|||||||
func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig, telemetry telemetry.TelemetryService) *Room {
|
func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig, telemetry telemetry.TelemetryService) *Room {
|
||||||
r := &Room{
|
r := &Room{
|
||||||
Room: proto.Clone(room).(*livekit.Room),
|
Room: proto.Clone(room).(*livekit.Room),
|
||||||
Logger: LoggerWithRoom(logger.Logger(logger.GetLogger()), livekit.RoomName(room.Name)),
|
Logger: LoggerWithRoom(logger.Logger(logger.GetLogger()), livekit.RoomName(room.Name), livekit.RoomID(room.Sid)),
|
||||||
config: config,
|
config: config,
|
||||||
audioConfig: audioConfig,
|
audioConfig: audioConfig,
|
||||||
telemetry: telemetry,
|
telemetry: telemetry,
|
||||||
@@ -86,6 +86,10 @@ func (r *Room) Name() livekit.RoomName {
|
|||||||
return livekit.RoomName(r.Room.Name)
|
return livekit.RoomName(r.Room.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Room) ID() livekit.RoomID {
|
||||||
|
return livekit.RoomID(r.Room.Sid)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Room) GetParticipant(identity livekit.ParticipantIdentity) types.LocalParticipant {
|
func (r *Room) GetParticipant(identity livekit.ParticipantIdentity) types.LocalParticipant {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
@@ -215,7 +219,6 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
|
|||||||
"pID", participant.ID(),
|
"pID", participant.ID(),
|
||||||
"participant", participant.Identity(),
|
"participant", participant.Identity(),
|
||||||
"protocol", participant.ProtocolVersion(),
|
"protocol", participant.ProtocolVersion(),
|
||||||
"roomID", r.Room.Sid,
|
|
||||||
"options", opts)
|
"options", opts)
|
||||||
|
|
||||||
if participant.IsRecorder() && !r.Room.ActiveRecording {
|
if participant.IsRecorder() && !r.Room.ActiveRecording {
|
||||||
@@ -450,7 +453,7 @@ func (r *Room) CloseIfEmpty() {
|
|||||||
func (r *Room) Close() {
|
func (r *Room) Close() {
|
||||||
r.closeOnce.Do(func() {
|
r.closeOnce.Do(func() {
|
||||||
close(r.closed)
|
close(r.closed)
|
||||||
r.Logger.Infow("closing room", "roomID", r.Room.Sid, "room", r.Room.Name)
|
r.Logger.Infow("closing room")
|
||||||
if r.onClose != nil {
|
if r.onClose != nil {
|
||||||
r.onClose()
|
r.onClose()
|
||||||
}
|
}
|
||||||
@@ -496,7 +499,7 @@ func (r *Room) sendRoomUpdateLocked() {
|
|||||||
|
|
||||||
err := p.SendRoomUpdate(r.Room)
|
err := p.SendRoomUpdate(r.Room)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Logger.Warnw("failed to send room update", err, "room", r.Room.Name, "participant", p.Identity())
|
r.Logger.Warnw("failed to send room update", err, "participant", p.Identity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ type LocalParticipant interface {
|
|||||||
//counterfeiter:generate . Room
|
//counterfeiter:generate . Room
|
||||||
type Room interface {
|
type Room interface {
|
||||||
Name() livekit.RoomName
|
Name() livekit.RoomName
|
||||||
|
ID() livekit.RoomID
|
||||||
UpdateSubscriptions(participant LocalParticipant, trackIDs []livekit.TrackID, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
UpdateSubscriptions(participant LocalParticipant, trackIDs []livekit.TrackID, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
||||||
UpdateSubscriptionPermissions(participant Participant, permissions *livekit.UpdateSubscriptionPermissions) error
|
UpdateSubscriptionPermissions(participant Participant, permissions *livekit.UpdateSubscriptionPermissions) error
|
||||||
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FakeRoom struct {
|
type FakeRoom struct {
|
||||||
|
IDStub func() livekit.RoomID
|
||||||
|
iDMutex sync.RWMutex
|
||||||
|
iDArgsForCall []struct {
|
||||||
|
}
|
||||||
|
iDReturns struct {
|
||||||
|
result1 livekit.RoomID
|
||||||
|
}
|
||||||
|
iDReturnsOnCall map[int]struct {
|
||||||
|
result1 livekit.RoomID
|
||||||
|
}
|
||||||
NameStub func() livekit.RoomName
|
NameStub func() livekit.RoomName
|
||||||
nameMutex sync.RWMutex
|
nameMutex sync.RWMutex
|
||||||
nameArgsForCall []struct {
|
nameArgsForCall []struct {
|
||||||
@@ -85,6 +95,59 @@ type FakeRoom struct {
|
|||||||
invocationsMutex sync.RWMutex
|
invocationsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) ID() livekit.RoomID {
|
||||||
|
fake.iDMutex.Lock()
|
||||||
|
ret, specificReturn := fake.iDReturnsOnCall[len(fake.iDArgsForCall)]
|
||||||
|
fake.iDArgsForCall = append(fake.iDArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.IDStub
|
||||||
|
fakeReturns := fake.iDReturns
|
||||||
|
fake.recordInvocation("ID", []interface{}{})
|
||||||
|
fake.iDMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) IDCallCount() int {
|
||||||
|
fake.iDMutex.RLock()
|
||||||
|
defer fake.iDMutex.RUnlock()
|
||||||
|
return len(fake.iDArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) IDCalls(stub func() livekit.RoomID) {
|
||||||
|
fake.iDMutex.Lock()
|
||||||
|
defer fake.iDMutex.Unlock()
|
||||||
|
fake.IDStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) IDReturns(result1 livekit.RoomID) {
|
||||||
|
fake.iDMutex.Lock()
|
||||||
|
defer fake.iDMutex.Unlock()
|
||||||
|
fake.IDStub = nil
|
||||||
|
fake.iDReturns = struct {
|
||||||
|
result1 livekit.RoomID
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) IDReturnsOnCall(i int, result1 livekit.RoomID) {
|
||||||
|
fake.iDMutex.Lock()
|
||||||
|
defer fake.iDMutex.Unlock()
|
||||||
|
fake.IDStub = nil
|
||||||
|
if fake.iDReturnsOnCall == nil {
|
||||||
|
fake.iDReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 livekit.RoomID
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.iDReturnsOnCall[i] = struct {
|
||||||
|
result1 livekit.RoomID
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) Name() livekit.RoomName {
|
func (fake *FakeRoom) Name() livekit.RoomName {
|
||||||
fake.nameMutex.Lock()
|
fake.nameMutex.Lock()
|
||||||
ret, specificReturn := fake.nameReturnsOnCall[len(fake.nameArgsForCall)]
|
ret, specificReturn := fake.nameReturnsOnCall[len(fake.nameArgsForCall)]
|
||||||
@@ -463,6 +526,8 @@ func (fake *FakeRoom) UpdateVideoLayersReturnsOnCall(i int, result1 error) {
|
|||||||
func (fake *FakeRoom) Invocations() map[string][][]interface{} {
|
func (fake *FakeRoom) Invocations() map[string][][]interface{} {
|
||||||
fake.invocationsMutex.RLock()
|
fake.invocationsMutex.RLock()
|
||||||
defer fake.invocationsMutex.RUnlock()
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.iDMutex.RLock()
|
||||||
|
defer fake.iDMutex.RUnlock()
|
||||||
fake.nameMutex.RLock()
|
fake.nameMutex.RLock()
|
||||||
defer fake.nameMutex.RUnlock()
|
defer fake.nameMutex.RUnlock()
|
||||||
fake.simulateScenarioMutex.RLock()
|
fake.simulateScenarioMutex.RLock()
|
||||||
|
|||||||
+8
-6
@@ -144,11 +144,13 @@ func LoggerWithParticipant(l logger.Logger, identity livekit.ParticipantIdentity
|
|||||||
return logger.Logger(lr)
|
return logger.Logger(lr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoggerWithRoom(l logger.Logger, name livekit.RoomName) logger.Logger {
|
func LoggerWithRoom(l logger.Logger, name livekit.RoomName, roomID livekit.RoomID) logger.Logger {
|
||||||
lr := logr.Logger(l)
|
lr := logr.Logger(l)
|
||||||
return logger.Logger(
|
if name != "" {
|
||||||
lr.WithValues(
|
lr = lr.WithValues("room", name)
|
||||||
"room", name,
|
}
|
||||||
),
|
if roomID != "" {
|
||||||
)
|
lr = lr.WithValues("roomID", roomID)
|
||||||
|
}
|
||||||
|
return logger.Logger(lr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
|||||||
defer rtc.Recover()
|
defer rtc.Recover()
|
||||||
|
|
||||||
pLogger := rtc.LoggerWithParticipant(
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name()),
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name(), room.ID()),
|
||||||
participant.Identity(), participant.ID(),
|
participant.Identity(), participant.ID(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ func (r *RoomManager) handleRTCMessage(_ context.Context, roomName livekit.RoomN
|
|||||||
|
|
||||||
participant := room.GetParticipant(identity)
|
participant := room.GetParticipant(identity)
|
||||||
pLogger := rtc.LoggerWithParticipant(
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName, room.ID()),
|
||||||
identity,
|
identity,
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pLogger := rtc.LoggerWithParticipant(
|
pLogger := rtc.LoggerWithParticipant(
|
||||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName, ""),
|
||||||
pi.Identity, "",
|
pi.Identity, "",
|
||||||
)
|
)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|||||||
Reference in New Issue
Block a user