Skip to content

Commit

Permalink
Add more debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Feb 10, 2025
1 parent d1f8296 commit b79f597
Show file tree
Hide file tree
Showing 28 changed files with 1,139 additions and 187 deletions.
12 changes: 12 additions & 0 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
3DA24A452C2AABC0005B959B /* KMPPubNub+Files.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA24A442C2AABC0005B959B /* KMPPubNub+Files.swift */; };
3DACC7F72AB88F8E00210B14 /* Data+CommonCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DACC7F62AB88F8E00210B14 /* Data+CommonCrypto.swift */; };
3DB2C4872C0F4B250060B8CF /* KMPStatusListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2C4862C0F4B250060B8CF /* KMPStatusListener.swift */; };
3DB692522D555AA5006702DC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB692512D555AA5006702DC /* Logger.swift */; };
3DB9255C2B7A2B89001B7E90 /* SubscriptionStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB925592B7A2B89001B7E90 /* SubscriptionStreamTests.swift */; };
3DB9255D2B7A2B89001B7E90 /* EventStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB9255A2B7A2B89001B7E90 /* EventStreamTests.swift */; };
3DB925602B7A2B9B001B7E90 /* SubscriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB9255F2B7A2B9B001B7E90 /* SubscriptionTests.swift */; };
Expand Down Expand Up @@ -1076,6 +1077,7 @@
3DA24A442C2AABC0005B959B /* KMPPubNub+Files.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KMPPubNub+Files.swift"; sourceTree = "<group>"; };
3DACC7F62AB88F8E00210B14 /* Data+CommonCrypto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+CommonCrypto.swift"; sourceTree = "<group>"; };
3DB2C4862C0F4B250060B8CF /* KMPStatusListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPStatusListener.swift; sourceTree = "<group>"; };
3DB692512D555AA5006702DC /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
3DB925592B7A2B89001B7E90 /* SubscriptionStreamTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionStreamTests.swift; sourceTree = "<group>"; };
3DB9255A2B7A2B89001B7E90 /* EventStreamTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventStreamTests.swift; sourceTree = "<group>"; };
3DB9255F2B7A2B9B001B7E90 /* SubscriptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2322,6 +2324,14 @@
path = KMP;
sourceTree = "<group>";
};
3DB692502D555A93006702DC /* Logger */ = {
isa = PBXGroup;
children = (
3DB692512D555AA5006702DC /* Logger.swift */,
);
path = Logger;
sourceTree = "<group>";
};
3DB925572B7A2B89001B7E90 /* Old */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2628,6 +2638,7 @@
3D34160A2BB5832E008558A0 /* PrivacyInfo.xcprivacy */,
OBJ_11 /* PubNub.swift */,
359152A022BA9AA30048842D /* PubNubConfiguration.swift */,
3DB692502D555A93006702DC /* Logger */,
3D8BAC0E2B8C96A40059A5C3 /* DependencyContainer */,
3D389FC12B35AF4A006928E7 /* EventEngine */,
35B0ACE4252BE37C00537A18 /* APIs */,
Expand Down Expand Up @@ -3721,6 +3732,7 @@
35089A0922E3C08D002BCC94 /* Error+PubNub.swift in Sources */,
3534D4E422C57659008E89FA /* PublishRouter.swift in Sources */,
35EE358C22E26A4D00E3F081 /* HTTPURLResponse+PubNub.swift in Sources */,
3DB692522D555AA5006702DC /* Logger.swift in Sources */,
3D389FEE2B35AF4A006928E7 /* SubscribeTransition.swift in Sources */,
3DB925822B7AA75F001B7E90 /* Subscribable.swift in Sources */,
3D7062C42D26AA20000729E1 /* KMPAppContextIncludeFields.swift in Sources */,
Expand Down
13 changes: 12 additions & 1 deletion Sources/PubNub/EventEngine/Core/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
notify listener: DispatcherListener<Event>
) {
invocations.forEach {
PubNub.log.debug(
"Received invocation: \($0)",
category: LogCategory.eventEngine.rawValue
)
switch $0 {
case .managed(let invocation):
executeEffect(
Expand All @@ -75,7 +79,14 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
storageId id: String,
notify listener: DispatcherListener<Event>
) {
effectsCache.put(effect: effect, with: id)
effectsCache.put(
effect: effect,
with: id
)
PubNub.log.debug(
"Dispatching Effect: \(effect)",
category: LogCategory.eventEngine.rawValue
)
effect.performTask { [weak effectsCache] results in
effectsCache?.removeEffect(id: id)
listener.onAnyInvocationCompleted(results)
Expand Down
8 changes: 8 additions & 0 deletions Sources/PubNub/EventEngine/Core/EventEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ class EventEngine<State, Event, Invocation: AnyEffectInvocation, Input> {
}

let transitionResult = transition.transition(from: currentState, event: event)
let newState = transitionResult.state
let invocations = transitionResult.invocations
let currentStateDescr = String(describing: currentState)
let newStateDescr = String(describing: newState)

PubNub.log.debug(
"Did transition from \(currentStateDescr) to \(newStateDescr)",
category: LogCategory.eventEngine.rawValue
)

state = transitionResult.state
onStateUpdated?(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ struct PresenceInput: Equatable {
return equalChannels && equalGroups
}
}

extension PresenceInput: CustomStringConvertible {
var description: String {
String.formattedDescription(self, arguments: [("channels", channelsSet), ("groups", groups)])
}
}
59 changes: 56 additions & 3 deletions Sources/PubNub/EventEngine/Presence/Presence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation

// MARK: - PresenceState

protocol PresenceState: Equatable {
protocol PresenceState: Equatable, CustomStringConvertible {
var input: PresenceInput { get }
}

Expand All @@ -24,6 +24,13 @@ extension PresenceState {
var groups: [String] {
input.groups
}

var description: String {
String.formattedDescription(
self,
arguments: [("input", input)]
)
}
}

//
Expand All @@ -37,25 +44,48 @@ extension Presence {
struct Heartbeating: PresenceState {
let input: PresenceInput
}
}

extension Presence {
struct HeartbeatCooldown: PresenceState {
let input: PresenceInput
}
}

extension Presence {
struct HeartbeatFailed: PresenceState {
let input: PresenceInput
let error: PubNubError
}
}

extension Presence.HeartbeatFailed {
var description: String {
String.formattedDescription(
self,
arguments: [("input", input), ("error", error.reason)]
)
}
}

extension Presence {
struct HeartbeatStopped: PresenceState {
let input: PresenceInput
}
}

extension Presence {
struct HeartbeatInactive: PresenceState {
let input: PresenceInput = .init()
}
}

extension Presence.HeartbeatInactive {
var description: String {
String.formattedDescription(self)
}
}

// MARK: - Presence Events

extension Presence {
Expand All @@ -80,13 +110,13 @@ extension Presence {
// MARK: - Presence Effect Invocations

extension Presence {
enum Invocation: AnyEffectInvocation {
enum Invocation: AnyEffectInvocation, CustomStringConvertible {
case heartbeat(channels: [String], groups: [String])
case leave(channels: [String], groups: [String])
case wait

// swiftlint:disable:next nesting
enum Cancellable: AnyCancellableInvocation {
enum Cancellable: AnyCancellableInvocation, CustomStringConvertible {
case wait

var id: String {
Expand All @@ -95,6 +125,12 @@ extension Presence {
return "Presence.ScheduleNextHeartbeat"
}
}
var description: String {
switch self {
case .wait:
return "Presence.Invocation.Cancellable.Wait"
}
}
}

var id: String {
Expand All @@ -107,5 +143,22 @@ extension Presence {
return "Presence.Leave"
}
}

var description: String {
switch self {
case let .heartbeat(channels, groups):
return String.formattedDescription(
"Presence.Invocation.Heartbeat",
arguments: [("channels", channels), ("groups", groups)]
)
case let .leave(channels, groups):
return String.formattedDescription(
"Presence.Invocation.Leave",
arguments: [("channels", channels), ("groups", groups)]
)
case .wait:
return "Presence.Invocation.Wait"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ class MessageCache {
}
}

struct EmitMessagesEffect: EffectHandler {
struct EmitMessagesEffect: EffectHandler, CustomStringConvertible {
let messages: [SubscribeMessagePayload]
let cursor: SubscribeCursor
let subscriptions: WeakSet<BaseSubscriptionListener>
let messageCache: MessageCache

var description: String {
String.formattedDescription(
self,
arguments: [
("messages", messages),
("cursor", cursor),
("subscriptions", subscriptions)
]
)
}

func performTask(completionBlock: @escaping ([Subscribe.Event]) -> Void) {
// Attempt to detect missed messages due to queue overflow
if messages.count >= 100 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ extension Dictionary where Key == String, Value == PubNubChannel {
return nil
}
}

extension SubscribeInput: CustomStringConvertible {
var description: String {
String.formattedDescription(self, arguments: [("channels", allSubscribedChannelNames), ("groups", allSubscribedGroupNames)])
}
}
Loading

0 comments on commit b79f597

Please sign in to comment.