Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]Small improvements in logs #651

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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