Skip to content

Commit 6b8a08b

Browse files
authored
Logging 6 (#1691)
* Refactor logging to use structured logging patterns for Windows media Update all logging statements to use structured logging with named placeholders and argument lists. Add logger.IsEnabled checks to guard value processing. Change logger in WindowsAudioEndPoint to static. Refactor video format logging in WindowsVideoEndPoint to only run when debug logging is enabled and use structured logging. * Refactor logging to use structured log messages in OpenAI real time Updated all log statements to use structured logging with named placeholders instead of interpolated strings. Added structured logging for data channel message payloads and removed direct JSON logging. These changes enhance log readability and facilitate better log analysis.
1 parent 67062c7 commit 6b8a08b

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/SIPSorcery.OpenAI.Realtime/WebRTC/WebRTCEndPoint.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ private RTCPeerConnection CreatePeerConnection(RTCConfiguration? pcConfig)
134134
// This call is synchronous when the WebRTC connection is not yet connected.
135135
var dataChannel = pc.createDataChannel(OPENAI_DATACHANNEL_NAME).Result;
136136

137-
pc.onconnectionstatechange += state => _logger.LogDebug($"Peer connection connected changed to {state}.");
138-
pc.OnTimeout += mediaType => _logger.LogDebug($"Timeout on media {mediaType}.");
139-
pc.oniceconnectionstatechange += state => _logger.LogDebug($"ICE connection state changed to {state}.");
137+
pc.onconnectionstatechange += state => _logger.LogDebug("Peer connection state changed to {ConnectionState}.", state);
138+
pc.OnTimeout += mediaType => _logger.LogDebug("Timeout on media {MediaType}.", mediaType);
139+
pc.oniceconnectionstatechange += state => _logger.LogDebug("ICE connection state changed to {IceConnectionState}.", state);
140140

141141
pc.onsignalingstatechange += () =>
142142
{
143143
if (pc.signalingState == RTCSignalingState.have_local_offer)
144144
{
145-
_logger.LogTrace($"Local SDP:\n{pc.localDescription.sdp}");
145+
_logger.LogTrace("Local SDP:\n{LocalSdp}", pc.localDescription.sdp);
146146
}
147147
else if (pc.signalingState is RTCSignalingState.have_remote_offer or RTCSignalingState.stable)
148148
{
149-
_logger.LogTrace($"Remote SDP:\n{pc.remoteDescription?.sdp}");
149+
_logger.LogTrace("Remote SDP:\n{RemoteSdp}", pc.remoteDescription?.sdp);
150150
}
151151
};
152152

@@ -197,10 +197,13 @@ public void SendDataChannelMessage(RealtimeEventBase message)
197197
return;
198198
}
199199

200-
_logger.LogDebug($"Sending initial response create to first call data channel {dc.label}.");
201-
_logger.LogTrace(message.ToJson());
200+
_logger.LogDebug("Sending initial response create to first call data channel {DataChannelLabel}.", dc.label);
202201

203-
dc.send(message.ToJson());
202+
var messageJson = message.ToJson();
203+
204+
_logger.LogTrace("Data channel message payload: {MessageJson}", messageJson);
205+
206+
dc.send(messageJson);
204207
},
205208
() => _logger.LogError("No peer connection available to send data channel message.")
206209
);

0 commit comments

Comments
 (0)