Skip to content

Commit 4754338

Browse files
Cleaned up logger comments.
1 parent 2530de7 commit 4754338

File tree

2 files changed

+72
-38
lines changed

2 files changed

+72
-38
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYLoggerMessages.m

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,53 +77,53 @@
7777

7878
// ---- Event Tracking ----
7979
// info
80-
NSString *const OPTLYLoggerMessagesConversionSuccess = @"Tracking event %@ for user %@.";
81-
NSString *const OPTLYLoggerMessagesActivationSuccess = @"Activating user %@ in experiment %@.";
80+
NSString *const OPTLYLoggerMessagesConversionSuccess = @"[EVENT DISPATCH] Tracking event %@ for user %@.";
81+
NSString *const OPTLYLoggerMessagesActivationSuccess = @"[EVENT DISPATCH] Activating user %@ in experiment %@.";
8282
// warning
83-
NSString *const OPTLYLoggerMessagesEventDispatcherInvalidInterval = @"Invalid event handler dispatch interval set - %ld";
84-
NSString *const OPTLYLoggerMessagesEventDispatcherInvalidTimeout = @"Invalid event handler dispatch timeout set - %ld";
83+
NSString *const OPTLYLoggerMessagesEventDispatcherInvalidInterval = @"[EVENT DISPATCH] Invalid event handler dispatch interval set: %ld.";
84+
NSString *const OPTLYLoggerMessagesEventDispatcherInvalidTimeout = @"[EVENT DISPATCH] Invalid event handler dispatch timeout set: %ld.";
8585
// debug
86-
NSString *const OPTLYLoggerMessagesDispatchingImpressionEvent = @"Dispatching impression event with params %@.";
87-
NSString *const OPTLYLoggerMessagesDispatchingConversionEvent = @"Dispatching conversion event with params %@.";
88-
NSString *const OPTLYLoggerMessagesEventDispatcherProperties = @"Event dispatcher values set: interval - %ld, timeout - %ld, max backoff retries - %ld";
89-
NSString *const OPTLYLoggerMessagesEventDispatcherNetworkTimerEnabled = @"Event dispatcher network timer enabled - %ld, %ld, %ld.";
90-
NSString *const OPTLYLoggerMessagesEventDispatcherNetworkTimerDisabled = @"Event dispatcher network timer disabled.";
91-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsNoEvents = @"No events to send for flushEvents call.";
92-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffSkipRetry = @"At dispatch call %ld. Skipping dispatch retry.";
86+
NSString *const OPTLYLoggerMessagesDispatchingImpressionEvent = @"[EVENT DISPATCH] Dispatching impression event with params %@.";
87+
NSString *const OPTLYLoggerMessagesDispatchingConversionEvent = @"[EVENT DISPATCH] Dispatching conversion event with params %@.";
88+
NSString *const OPTLYLoggerMessagesEventDispatcherProperties = @"[EVENT DISPATCH] Properties set: %ld [interval], %ld [timeout], %ld [max retries].";
89+
NSString *const OPTLYLoggerMessagesEventDispatcherNetworkTimerEnabled = @"[EVENT DISPATCH] Network timer enabled with properties: %ld [interval], %ld [timeout], %ld [max retries].";
90+
NSString *const OPTLYLoggerMessagesEventDispatcherNetworkTimerDisabled = @"[EVENT DISPATCH] Network timer disabled.";
91+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsNoEvents = @"[EVENT DISPATCH] No events to send for flushEvents call.";
92+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffSkipRetry = @"[EVENT DISPATCH] At dispatch call %ld. Skipping dispatch retry.";
9393
NSString *const OPTLYLoggerMessagesEventDispatcherEventDispatchFlushSavedEventNoEvents = @"No %@ events to send for flush saved events call.";
94-
NSString *const OPTLYLoggerMessagesEventDispatcherEventDispatchSuccess = @"%@ event sent with parameters - %@.";
95-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffMaxRetries = @"Attempt to dispatch saved events failed. Re-tries have exceeded max allowed time - %ld.";
96-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventSuccess = @"%@ event successfully sent with parameters - %@. Removing event from storage.";
97-
NSString *const OPTLYLoggerMessagesEventDispatcherEventDispatchFailed = @"%@ event not sent. Parameters - %@. Error received - %@. Saving event...";
98-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventFailure = @"%@ event not sent. Parameters - %@.";
99-
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventRetrievalFailure = @"Error retrieving saved event data - %@";
94+
NSString *const OPTLYLoggerMessagesEventDispatcherEventDispatchSuccess = @"[EVENT DISPATCH] %@ event sent with parameters: %@.";
95+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushEventsBackoffMaxRetries = @"[EVENT DISPATCH] Attempt to dispatch saved events failed. Retries have exceeded max allowed time: %ld.";
96+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventSuccess = @"[EVENT DISPATCH] %@ event successfully sent with parameters: %@. Removing event from storage.";
97+
NSString *const OPTLYLoggerMessagesEventDispatcherEventDispatchFailed = @"[EVENT DISPATCH] %@ event not sent. Saving event. Parameters: %@. Error received: %@.";
98+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventFailure = @"[EVENT DISPATCH] %@ event not sent and will not be removed from the queue. Parameters: %@.";
99+
NSString *const OPTLYLoggerMessagesEventDispatcherFlushSavedEventRetrievalFailure = @"[EVENT DISPATCH] Error retrieving saved event data: %@.";
100100
// error
101-
NSString *const OPTLYLoggerMessagesEventNotTracked = @"Not tracking event %@ for experiment %@."; // event key, userId
102-
NSString *const OPTLYLoggerMessagesActivationFailure = @"Not activating user %@ for experiment %@.";
101+
NSString *const OPTLYLoggerMessagesEventNotTracked = @"[EVENT DISPATCH] Not tracking event %@ for experiment %@."; // event key, userId
102+
NSString *const OPTLYLoggerMessagesActivationFailure = @"[EVENT DISPATCH] Not activating user %@ for experiment %@.";
103103

104104

105105
// ---- Data Store ----
106106
// File Manager
107107
// debug
108-
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveAllFilesError = @"File manager remove all files error - %@";
109-
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveFilesForDataTypeError = @"File manager remove files for data type - %ld, error - %@";
110-
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveFileForDataTypeError = @"File manager remove file for data type - %ld, file name - %@, error - %@";
111-
NSString *const OPTLYLoggerMessagesDataStoreFileManagerGetFile = @"File manager get file for data type - %ld, file name - %@, error - %@";
112-
NSString *const OPTLYLoggerMessagesDataStoreFileManagerSaveFile = @"File manager save file for data type - %ld, file name - %@, error - %@";
108+
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveAllFilesError = @"[FILE MANAGER] Remove all files error: %@.";
109+
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveFilesForDataTypeError = @"[FILE MANAGER] Error removing files for data type %ld. Error: %@.";
110+
NSString *const OPTLYLoggerMessagesDataStoreFileManagerRemoveFileForDataTypeError = @"[FILE MANAGER] Error removing file for data type %ld. File name: %@. Error: %@.";
111+
NSString *const OPTLYLoggerMessagesDataStoreFileManagerGetFile = @"[FILE MANAGER] Error gettomg file for data type %ld. File name: %@. Error: %@.";
112+
NSString *const OPTLYLoggerMessagesDataStoreFileManagerSaveFile = @"[FILE MANAGER] Error saving file for data type %ld. File name: %@. Error: %@.";
113113

114114
// Database
115115
// debug
116-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseCreateTableError = @"Creating database table %@ error - %@";
117-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseSaveError = @"Database save error: data - %@, eventType - %ld, cachedData - %u, error - %@";
118-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetError = @"Database get error: number of events - %ld, eventType - %ld, cachedData - %u, error - %@";
119-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEvents = @"Database get number of events error: cachedData - %u, eventType - %ld, error - %@.";
120-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveError = @"Database remove error: number of events - %ld, eventType - %ld, cachedData - %u, error - %@";
116+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseCreateTableError = @"[DATABASE] Error creating table %@. Error: %@.";
117+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseSaveError = @"[DATABASE] Error saving database. Data: %@, eventType: %ld, cachedData: %u, error: %@.";
118+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetError = @"[DATABASE] Error getting events. Number of events requested: %ld, eventType: %ld, cachedData: %u, error: %@.";
119+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEvents = @"[DATABASE] Error getting number of events. cachedData: %u, eventType: %ld, error: %@.";
120+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveError = @"[DATABASE] Error removing data. Number of events to remove: %ld, eventType: %ld, cachedData: %u, error: %@.";
121121
// warning
122-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNoEvents = @"Database get event returned no event: eventType - %ld, cachedData - %u";
123-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseSaveTVOSWarning = @"tvOS can only save to cached data: data - %@, eventType - %ld.";
124-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetTVOSWarning = @"tvOS can only get data from cache: number of events - %ld, eventType - %ld.";
125-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEventsTVOSWarning = @"tvOS can only get number of events from cache: eventType - %ld.";
126-
NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveTVOSWarning = @"tvOS can only remove data from cache: number of events - %ld, eventType - %ld.";
122+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNoEvents = @"[DATABASE] Get event returned no event. eventType: %ld, cachedData: %u.";
123+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseSaveTVOSWarning = @"[DATABASE] tvOS can only save to cached data. Data: %@, eventType: %ld.";
124+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetTVOSWarning = @"[DATABASE] tvOS can only get data from cache. Number of events: %ld, eventType: %ld.";
125+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEventsTVOSWarning = @"[DATABASE] tvOS can only get number of events from cache. eventType: %ld.";
126+
NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveTVOSWarning = @"[DATABASE] tvOS can only remove data from cache> Number of events: %ld, eventType: %ld.";
127127

128128

129129

OptimizelySDKEventDispatcher/OptimizelySDKEventDispatcher/OPTLYEventDispatcher.m

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
***************************************************************************/
1616

1717
#import "OPTLYEventDispatcher.h"
18+
#import <OptimizelySDKShared/Reachability.h>
19+
1820

1921
// --- Event URLs ----
22+
NSString * const OPTLYEventDispatcherHostName = @"https://logx.optimizely.com";
2023
NSString * const OPTLYEventDispatcherImpressionEventURL = @"https://logx.optimizely.com/log/decision";
2124
NSString * const OPTLYEventDispatcherConversionEventURL = @"https://logx.optimizely.com/log/event";
2225

@@ -391,6 +394,10 @@ - (void)flushSavedEvents:(OPTLYDataStoreEventType)eventType
391394
NSInteger totalNumberOfEvents = [self.dataStore numberOfEvents:eventType cachedData:cachedData error:&error];
392395
NSArray *events = [self.dataStore getAllEvents:eventType cachedData:cachedData error:&error];
393396

397+
if (!totalNumberOfEvents) {
398+
return;
399+
}
400+
394401
if (error) {
395402
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesEventDispatcherFlushSavedEventFailure, eventName, nil];
396403
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
@@ -410,6 +417,11 @@ - (void)setupApplicationNotificationHandlers {
410417
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
411418
UIApplication *app = [UIApplication sharedApplication];
412419

420+
[defaultCenter addObserver:self
421+
selector:@selector(applicationDidFinishLaunching:)
422+
name:UIApplicationDidFinishLaunchingNotification
423+
object:app];
424+
413425
[defaultCenter addObserver:self
414426
selector:@selector(applicationDidBecomeActive:)
415427
name:UIApplicationDidBecomeActiveNotification
@@ -436,13 +448,38 @@ - (void)setupApplicationNotificationHandlers {
436448
object:app];
437449
}
438450

451+
- (void)applicationDidFinishLaunching:(id)notificaton {
452+
453+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityDidChange:) name:kReachabilityChangedNotification object:nil];
454+
455+
// Initialize Reachability
456+
Reachability *hostReachability = [Reachability reachabilityWithHostName:OPTLYEventDispatcherHostName];
457+
Reachability *internetReachability = [Reachability reachabilityForInternetConnection];
458+
// Start Monitoring
459+
[internetReachability startNotifier];
460+
[hostReachability startNotifier];
461+
462+
OPTLYLogInfo(@"applicationDidBecomeActive");
463+
}
464+
465+
- (void)reachabilityDidChange:(NSNotification *)notification {
466+
Reachability *reachability = (Reachability *)[notification object];
467+
468+
if ([reachability currentReachabilityStatus] != NotReachable) {
469+
OPTLYLogInfo(@"Network is reachable.");
470+
} else {
471+
OPTLYLogInfo(@"Network is unreachable");
472+
}
473+
}
474+
439475
- (void)applicationDidBecomeActive:(id)notificaton {
440476
[self flushEvents];
441477
OPTLYLogInfo(@"applicationDidBecomeActive");
442478
}
443479

444480
- (void)applicationDidEnterBackground:(id)notification {
445481
[self flushEvents];
482+
//[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
446483
OPTLYLogInfo(@"applicationDidEnterBackground");
447484
}
448485

@@ -456,13 +493,10 @@ - (void)applicationWillResignActive:(id)notification {
456493

457494
- (void)applicationWillTerminate:(id)notification {
458495
[self flushEvents];
496+
//[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];
459497
OPTLYLogInfo(@"applicationWillTerminate");
460498
}
461499

462-
- (void)dealloc {
463-
[[NSNotificationCenter defaultCenter] removeObserver:self];
464-
}
465-
466500
# pragma mark - Helper Methods
467501
- (BOOL)haveEventsToSend:(OPTLYDataStoreEventType)eventType cachedData:(BOOL)cachedData
468502
{

0 commit comments

Comments
 (0)