Skip to content

Commit 7ed4abe

Browse files
Cleaned up logs.
1 parent 4336f63 commit 7ed4abe

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYLoggerMessages.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ extern NSString *const OPTLYLoggerMessagesUserProfileRemoveVariationNotFound;
133133
extern NSString *const OPTLYLoggerMessagesBucketerSavingUserData;
134134
extern NSString *const OPTLYLoggerMessagesBucketerUserDataRetrieved;
135135

136+
// ---- Datafile Nanager ----
137+
// Info
138+
extern NSString *const OPTLYLoggerMessagesDatafileManagerDatafileDownloading;
139+
extern NSString *const OPTLYLoggerMessagesDatafileManagerDatafileDownloaded;
140+
// Debug
141+
extern NSString *const OPTLYLoggerMessagesDatafileManagerLastModifiedDate;
142+
extern NSString *const OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedNoChanges;
143+
extern NSString *const OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError;
144+
extern NSString *const OPTLYLoggerMessagesDatafileManagerLastModifedDate;
145+
extern NSString *const OPTLYLoggerMessagesDatafileManagerLastModifedDateNotFound;
146+
136147
@interface OPTLYLoggerMessages : NSObject
137148

138149
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYLoggerMessages.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@
133133
NSString *const OPTLYLoggerMessagesBucketerSavingUserData = @"Saving bucketing data for user: %@, experiment: %@, variation: %@.";
134134
NSString *const OPTLYLoggerMessagesBucketerUserDataRetrieved = @"Retrieved bucketing data for user: %@, experiment: %@, variation: %@.";
135135

136+
// ---- Datafile Nanager ----
137+
// Info
138+
NSString *const OPTLYLoggerMessagesDatafileManagerDatafileDownloading = @"[DATAFILE MANAGER] Downloading datafile for project %@.";
139+
NSString *const OPTLYLoggerMessagesDatafileManagerDatafileDownloaded = @"[DATAFILE MANAGER] Datafile for project %@ downloaded. Saving datafile and last modified date: %@.";
140+
// Debug
141+
NSString *const OPTLYLoggerMessagesDatafileManagerLastModifiedDate = @"[DATAFILE MANAGER] Datafile was last modified on %@.";
142+
NSString *const OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedNoChanges = @"[DATAFILE MANAGER] Datafile for project %@ NOT downloaded. No datafile changes have been made.";
143+
NSString *const OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError = @"[DATAFILE MANAGER] Datafile for project %@ NOT downloaded. Error received: %@.";
144+
NSString *const OPTLYLoggerMessagesDatafileManagerLastModifedDate = @"[DATAFILE MANAGER] Last modified date %@ found for project %@.";
145+
NSString *const OPTLYLoggerMessagesDatafileManagerLastModifedDateNotFound = @"[DATAFILE MANAGER] Last modified date not found for project %@.";
146+
136147
@implementation OPTLYLoggerMessages
137148

138149
@end

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,46 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
6262
}
6363

6464
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
65-
OPTLYLogInfo(@"Downloading datafile: %@", projectId);
65+
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloading, projectId];
66+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
6667

6768
NSString *lastSavedModifiedDate = [self getLastModifiedDate:projectId];
69+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifiedDate, lastSavedModifiedDate];
70+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
71+
6872
[self.networkService downloadProjectConfig:self.projectId
6973
lastModified:lastSavedModifiedDate
7074
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
75+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
76+
NSInteger statusCode = [httpResponse statusCode];
77+
NSString *logMessage = @"";
7178
if (error != nil) {
7279
[self.errorHandler handleError:error];
7380
}
74-
else if ([(NSHTTPURLResponse *)response statusCode] == 200) { // got datafile OK
81+
else if (statusCode == 200) { // got datafile OK
7582
[self saveDatafile:data];
7683

7784
// save the last modified date
78-
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
85+
7986
NSDictionary *dictionary = [httpResponse allHeaderFields];
8087
NSString *lastModifiedDate = [dictionary valueForKey:@"Last-Modified"];
8188
[self saveLastModifiedDate:lastModifiedDate project:projectId];
82-
OPTLYLogInfo(@"Datafile for project ID %@ downloaded. Saving datafile and last modified date: %@", lastModifiedDate);
89+
90+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloaded, projectId, lastModifiedDate];
91+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
92+
}
93+
else if (statusCode == 304) {
94+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedNoChanges, projectId];
95+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
8396
}
8497
else {
8598
// TODO: Josh W. handle bad response
99+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError, projectId, error];
100+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
86101
}
102+
103+
104+
87105
// call the completion handler
88106
if (completion != nil) {
89107
completion(data, response, error);
@@ -126,9 +144,9 @@ - (nullable NSString *)getLastModifiedDate:(nonnull NSString *)projectId {
126144

127145
NSString *logMessage = @"";
128146
if ([lastModifiedDate length]) {
129-
logMessage = [NSString stringWithFormat:@"[DATAFILE MANAGER] Last modified date %@ found for project %@.", lastModifiedDate, projectId];
147+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifedDate, lastModifiedDate, projectId];
130148
} else {
131-
logMessage = [NSString stringWithFormat:@"[DATAFILE MANAGER] Last modified date not found for project %@.", projectId];
149+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifedDateNotFound, projectId];
132150
}
133151
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
134152

OptimizelySDKShared/OptimizelySDKShared/OPTLYHTTPRequestManager.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ - (void)GETIfModifiedSince:(nonnull NSString *)lastModifiedDate
102102

103103
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
104104
NSURLSessionDataTask *dataTask = [ephemeralSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
105-
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
106-
107-
int responseCode = (int)[httpResponse statusCode];
108-
OPTLYLogInfo(@"All headers: %@", [httpResponse allHeaderFields]);
109-
OPTLYLogInfo(@"Status code:: %d", responseCode);
110-
111105
if (completion) {
112106
completion(data, response, error);
113107
}

0 commit comments

Comments
 (0)