Skip to content

Commit

Permalink
[Enhancement]Small improvements in logs (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Feb 13, 2025
1 parent 30a5366 commit e1cd6d3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DemoApp/Sources/Components/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ final class AppState: ObservableObject {
}
} else if let pushToken, !pushToken.isEmpty {
deferSetDevice = true
log.debug("Deferring push notification setup for token: \(pushToken)")
log.debug("Deferring push notification setup for token:\(pushToken)")
} else {
log.debug("Clearing up push notification token.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ enum AuthenticationProvider {
return UserToken(rawValue: tokenResponse.token)
}
}()
log.debug("Authentication info userId:\(tokenResponse.userId) apiKey:\(tokenResponse.apiKey) token:\(token)")
log.debug("Authentication response: \(tokenResponse)")
return token
}
}
3 changes: 2 additions & 1 deletion DemoApp/Sources/Models/TokenResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//

import Foundation
import StreamVideo

struct TokenResponse: Codable {
struct TokenResponse: Codable, ReflectiveStringConvertible {
let userId: String
let token: String
let apiKey: String
Expand Down
4 changes: 2 additions & 2 deletions Sources/StreamVideo/Utils/Logger/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ extension Data {
/// Converts the data into a pretty-printed JSON string. Use only for debug purposes since this operation can be expensive.
var debugPrettyPrintedJSON: String {
do {
let jsonObject = try JSONSerialization.jsonObject(with: self, options: [.allowFragments])
let jsonObject = try JSONSerialization.jsonObject(with: self, options: [])
let prettyPrintedData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted])
return String(data: prettyPrintedData, encoding: .utf8) ?? "Error: Data to String decoding failed."
} catch {
return "JSON decoding failed with error: \(error)"
return "<not available string representation>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,21 @@ class URLSessionWebSocketEngine: NSObject, WebSocketEngine {

private func doRead() {
task?.receive { [weak self] result in
log.debug("received new event \(result)", subsystems: .webSocket)
guard let self = self, task != nil else {
return
}

switch result {
case let .success(message):
if case let .data(data) = message {
log.debug("Received webSocket message: \(data.debugPrettyPrintedJSON)", subsystems: .webSocket)
self.callbackQueue.async { [weak self] in
guard self?.task != nil else { return }
self?.delegate?.webSocketDidReceiveMessage(data)
}
} else if case let .string(string) = message {
let messageData = Data(string.utf8)
log.debug("Received webSocket message:\(messageData.debugPrettyPrintedJSON)", subsystems: .webSocket)
self.callbackQueue.async { [weak self] in
guard self?.task != nil else { return }
self?.delegate?.webSocketDidReceiveMessage(messageData)
Expand All @@ -126,7 +127,7 @@ class URLSessionWebSocketEngine: NSObject, WebSocketEngine {
self.doRead()

case let .failure(error):
log.error("Failed receiving Web Socket Message", subsystems: .webSocket, error: error)
log.error("Failed while trying to receive webSocket message.", subsystems: .webSocket, error: error)
}
}
}
Expand Down

0 comments on commit e1cd6d3

Please sign in to comment.