Skip to content

Commit b79f597

Browse files
committed
Add more debug logs
1 parent d1f8296 commit b79f597

28 files changed

+1139
-187
lines changed

PubNub.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@
454454
3DA24A452C2AABC0005B959B /* KMPPubNub+Files.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA24A442C2AABC0005B959B /* KMPPubNub+Files.swift */; };
455455
3DACC7F72AB88F8E00210B14 /* Data+CommonCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DACC7F62AB88F8E00210B14 /* Data+CommonCrypto.swift */; };
456456
3DB2C4872C0F4B250060B8CF /* KMPStatusListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2C4862C0F4B250060B8CF /* KMPStatusListener.swift */; };
457+
3DB692522D555AA5006702DC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB692512D555AA5006702DC /* Logger.swift */; };
457458
3DB9255C2B7A2B89001B7E90 /* SubscriptionStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB925592B7A2B89001B7E90 /* SubscriptionStreamTests.swift */; };
458459
3DB9255D2B7A2B89001B7E90 /* EventStreamTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB9255A2B7A2B89001B7E90 /* EventStreamTests.swift */; };
459460
3DB925602B7A2B9B001B7E90 /* SubscriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DB9255F2B7A2B9B001B7E90 /* SubscriptionTests.swift */; };
@@ -1076,6 +1077,7 @@
10761077
3DA24A442C2AABC0005B959B /* KMPPubNub+Files.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KMPPubNub+Files.swift"; sourceTree = "<group>"; };
10771078
3DACC7F62AB88F8E00210B14 /* Data+CommonCrypto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+CommonCrypto.swift"; sourceTree = "<group>"; };
10781079
3DB2C4862C0F4B250060B8CF /* KMPStatusListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPStatusListener.swift; sourceTree = "<group>"; };
1080+
3DB692512D555AA5006702DC /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
10791081
3DB925592B7A2B89001B7E90 /* SubscriptionStreamTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionStreamTests.swift; sourceTree = "<group>"; };
10801082
3DB9255A2B7A2B89001B7E90 /* EventStreamTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventStreamTests.swift; sourceTree = "<group>"; };
10811083
3DB9255F2B7A2B9B001B7E90 /* SubscriptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionTests.swift; sourceTree = "<group>"; };
@@ -2322,6 +2324,14 @@
23222324
path = KMP;
23232325
sourceTree = "<group>";
23242326
};
2327+
3DB692502D555A93006702DC /* Logger */ = {
2328+
isa = PBXGroup;
2329+
children = (
2330+
3DB692512D555AA5006702DC /* Logger.swift */,
2331+
);
2332+
path = Logger;
2333+
sourceTree = "<group>";
2334+
};
23252335
3DB925572B7A2B89001B7E90 /* Old */ = {
23262336
isa = PBXGroup;
23272337
children = (
@@ -2628,6 +2638,7 @@
26282638
3D34160A2BB5832E008558A0 /* PrivacyInfo.xcprivacy */,
26292639
OBJ_11 /* PubNub.swift */,
26302640
359152A022BA9AA30048842D /* PubNubConfiguration.swift */,
2641+
3DB692502D555A93006702DC /* Logger */,
26312642
3D8BAC0E2B8C96A40059A5C3 /* DependencyContainer */,
26322643
3D389FC12B35AF4A006928E7 /* EventEngine */,
26332644
35B0ACE4252BE37C00537A18 /* APIs */,
@@ -3721,6 +3732,7 @@
37213732
35089A0922E3C08D002BCC94 /* Error+PubNub.swift in Sources */,
37223733
3534D4E422C57659008E89FA /* PublishRouter.swift in Sources */,
37233734
35EE358C22E26A4D00E3F081 /* HTTPURLResponse+PubNub.swift in Sources */,
3735+
3DB692522D555AA5006702DC /* Logger.swift in Sources */,
37243736
3D389FEE2B35AF4A006928E7 /* SubscribeTransition.swift in Sources */,
37253737
3DB925822B7AA75F001B7E90 /* Subscribable.swift in Sources */,
37263738
3D7062C42D26AA20000729E1 /* KMPAppContextIncludeFields.swift in Sources */,

Sources/PubNub/EventEngine/Core/Dispatcher.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
5050
notify listener: DispatcherListener<Event>
5151
) {
5252
invocations.forEach {
53+
PubNub.log.debug(
54+
"Received invocation: \($0)",
55+
category: LogCategory.eventEngine.rawValue
56+
)
5357
switch $0 {
5458
case .managed(let invocation):
5559
executeEffect(
@@ -75,7 +79,14 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
7579
storageId id: String,
7680
notify listener: DispatcherListener<Event>
7781
) {
78-
effectsCache.put(effect: effect, with: id)
82+
effectsCache.put(
83+
effect: effect,
84+
with: id
85+
)
86+
PubNub.log.debug(
87+
"Dispatching Effect: \(effect)",
88+
category: LogCategory.eventEngine.rawValue
89+
)
7990
effect.performTask { [weak effectsCache] results in
8091
effectsCache?.removeEffect(id: id)
8192
listener.onAnyInvocationCompleted(results)

Sources/PubNub/EventEngine/Core/EventEngine.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ class EventEngine<State, Event, Invocation: AnyEffectInvocation, Input> {
6666
}
6767

6868
let transitionResult = transition.transition(from: currentState, event: event)
69+
let newState = transitionResult.state
6970
let invocations = transitionResult.invocations
71+
let currentStateDescr = String(describing: currentState)
72+
let newStateDescr = String(describing: newState)
73+
74+
PubNub.log.debug(
75+
"Did transition from \(currentStateDescr) to \(newStateDescr)",
76+
category: LogCategory.eventEngine.rawValue
77+
)
7078

7179
state = transitionResult.state
7280
onStateUpdated?(state)

Sources/PubNub/EventEngine/Presence/Helpers/PresenceInput.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ struct PresenceInput: Equatable {
5656
return equalChannels && equalGroups
5757
}
5858
}
59+
60+
extension PresenceInput: CustomStringConvertible {
61+
var description: String {
62+
String.formattedDescription(self, arguments: [("channels", channelsSet), ("groups", groups)])
63+
}
64+
}

Sources/PubNub/EventEngine/Presence/Presence.swift

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212

1313
// MARK: - PresenceState
1414

15-
protocol PresenceState: Equatable {
15+
protocol PresenceState: Equatable, CustomStringConvertible {
1616
var input: PresenceInput { get }
1717
}
1818

@@ -24,6 +24,13 @@ extension PresenceState {
2424
var groups: [String] {
2525
input.groups
2626
}
27+
28+
var description: String {
29+
String.formattedDescription(
30+
self,
31+
arguments: [("input", input)]
32+
)
33+
}
2734
}
2835

2936
//
@@ -37,25 +44,48 @@ extension Presence {
3744
struct Heartbeating: PresenceState {
3845
let input: PresenceInput
3946
}
47+
}
4048

49+
extension Presence {
4150
struct HeartbeatCooldown: PresenceState {
4251
let input: PresenceInput
4352
}
53+
}
4454

55+
extension Presence {
4556
struct HeartbeatFailed: PresenceState {
4657
let input: PresenceInput
4758
let error: PubNubError
4859
}
60+
}
4961

62+
extension Presence.HeartbeatFailed {
63+
var description: String {
64+
String.formattedDescription(
65+
self,
66+
arguments: [("input", input), ("error", error.reason)]
67+
)
68+
}
69+
}
70+
71+
extension Presence {
5072
struct HeartbeatStopped: PresenceState {
5173
let input: PresenceInput
5274
}
75+
}
5376

77+
extension Presence {
5478
struct HeartbeatInactive: PresenceState {
5579
let input: PresenceInput = .init()
5680
}
5781
}
5882

83+
extension Presence.HeartbeatInactive {
84+
var description: String {
85+
String.formattedDescription(self)
86+
}
87+
}
88+
5989
// MARK: - Presence Events
6090

6191
extension Presence {
@@ -80,13 +110,13 @@ extension Presence {
80110
// MARK: - Presence Effect Invocations
81111

82112
extension Presence {
83-
enum Invocation: AnyEffectInvocation {
113+
enum Invocation: AnyEffectInvocation, CustomStringConvertible {
84114
case heartbeat(channels: [String], groups: [String])
85115
case leave(channels: [String], groups: [String])
86116
case wait
87117

88118
// swiftlint:disable:next nesting
89-
enum Cancellable: AnyCancellableInvocation {
119+
enum Cancellable: AnyCancellableInvocation, CustomStringConvertible {
90120
case wait
91121

92122
var id: String {
@@ -95,6 +125,12 @@ extension Presence {
95125
return "Presence.ScheduleNextHeartbeat"
96126
}
97127
}
128+
var description: String {
129+
switch self {
130+
case .wait:
131+
return "Presence.Invocation.Cancellable.Wait"
132+
}
133+
}
98134
}
99135

100136
var id: String {
@@ -107,5 +143,22 @@ extension Presence {
107143
return "Presence.Leave"
108144
}
109145
}
146+
147+
var description: String {
148+
switch self {
149+
case let .heartbeat(channels, groups):
150+
return String.formattedDescription(
151+
"Presence.Invocation.Heartbeat",
152+
arguments: [("channels", channels), ("groups", groups)]
153+
)
154+
case let .leave(channels, groups):
155+
return String.formattedDescription(
156+
"Presence.Invocation.Leave",
157+
arguments: [("channels", channels), ("groups", groups)]
158+
)
159+
case .wait:
160+
return "Presence.Invocation.Wait"
161+
}
162+
}
110163
}
111164
}

Sources/PubNub/EventEngine/Subscribe/Effects/EmitMessagesEffect.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ class MessageCache {
3434
}
3535
}
3636

37-
struct EmitMessagesEffect: EffectHandler {
37+
struct EmitMessagesEffect: EffectHandler, CustomStringConvertible {
3838
let messages: [SubscribeMessagePayload]
3939
let cursor: SubscribeCursor
4040
let subscriptions: WeakSet<BaseSubscriptionListener>
4141
let messageCache: MessageCache
4242

43+
var description: String {
44+
String.formattedDescription(
45+
self,
46+
arguments: [
47+
("messages", messages),
48+
("cursor", cursor),
49+
("subscriptions", subscriptions)
50+
]
51+
)
52+
}
53+
4354
func performTask(completionBlock: @escaping ([Subscribe.Event]) -> Void) {
4455
// Attempt to detect missed messages due to queue overflow
4556
if messages.count >= 100 {

Sources/PubNub/EventEngine/Subscribe/Helpers/SubscribeInput.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,9 @@ extension Dictionary where Key == String, Value == PubNubChannel {
177177
return nil
178178
}
179179
}
180+
181+
extension SubscribeInput: CustomStringConvertible {
182+
var description: String {
183+
String.formattedDescription(self, arguments: [("channels", allSubscribedChannelNames), ("groups", allSubscribedGroupNames)])
184+
}
185+
}

0 commit comments

Comments
 (0)