Skip to content

Commit 4eea246

Browse files
authored
Log to console Data Collection flag value and source (#1811)
* Log to console Data Collection flag value and source This will log the source and value of the `dataCollectionDefaultEnabled` flag. This is for Issue #1768. * Put alreadyOutputDataCollectionFlag behind ifdef This avoids having the property in non-debug builds. * PR feedback Added a logging message when explicitly setting the data collection flag. * Copy-paste error Fixed a missed change in the ternary check.
1 parent 074f520 commit 4eea246

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Firebase/Core/FIRApp.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ @interface FIRApp ()
8989

9090
@property(nonatomic) BOOL alreadySentDeleteNotification;
9191

92+
#ifdef DEBUG
93+
@property(nonatomic) BOOL alreadyOutputDataCollectionFlag;
94+
#endif // DEBUG
95+
9296
@end
9397

9498
@implementation FIRApp
@@ -359,6 +363,12 @@ - (FIROptions *)options {
359363
}
360364

361365
- (void)setDataCollectionDefaultEnabled:(BOOL)dataCollectionDefaultEnabled {
366+
#ifdef DEBUG
367+
FIRLogDebug(kFIRLoggerCore, @"I-COR000034", @"Explicitly %@ data collection flag.",
368+
dataCollectionDefaultEnabled ? @"enabled" : @"disabled");
369+
self.alreadyOutputDataCollectionFlag = YES;
370+
#endif // DEBUG
371+
362372
NSString *key =
363373
[NSString stringWithFormat:kFIRGlobalAppDataCollectionEnabledDefaultsKeyFormat, self.name];
364374
[[NSUserDefaults standardUserDefaults] setBool:dataCollectionDefaultEnabled forKey:key];
@@ -385,6 +395,13 @@ - (BOOL)isDataCollectionDefaultEnabled {
385395
// Check if it's been manually set before in code, and use that as the higher priority value.
386396
NSNumber *defaultsObject = [[self class] readDataCollectionSwitchFromUserDefaultsForApp:self];
387397
if (defaultsObject != nil) {
398+
#ifdef DEBUG
399+
if (!self.alreadyOutputDataCollectionFlag) {
400+
FIRLogDebug(kFIRLoggerCore, @"I-COR000031", @"Data Collection flag is %@ in user defaults.",
401+
[defaultsObject boolValue] ? @"enabled" : @"disabled");
402+
self.alreadyOutputDataCollectionFlag = YES;
403+
}
404+
#endif // DEBUG
388405
return [defaultsObject boolValue];
389406
}
390407

@@ -393,9 +410,22 @@ - (BOOL)isDataCollectionDefaultEnabled {
393410
// no performance impact calling multiple times.
394411
NSNumber *collectionEnabledPlistValue = [[self class] readDataCollectionSwitchFromPlist];
395412
if (collectionEnabledPlistValue != nil) {
413+
#ifdef DEBUG
414+
if (!self.alreadyOutputDataCollectionFlag) {
415+
FIRLogDebug(kFIRLoggerCore, @"I-COR000032", @"Data Collection flag is %@ in plist.",
416+
[collectionEnabledPlistValue boolValue] ? @"enabled" : @"disabled");
417+
self.alreadyOutputDataCollectionFlag = YES;
418+
}
419+
#endif // DEBUG
396420
return [collectionEnabledPlistValue boolValue];
397421
}
398422

423+
#ifdef DEBUG
424+
if (!self.alreadyOutputDataCollectionFlag) {
425+
FIRLogDebug(kFIRLoggerCore, @"I-COR000033", @"Data Collection flag is not set.");
426+
self.alreadyOutputDataCollectionFlag = YES;
427+
}
428+
#endif // DEBUG
399429
return YES;
400430
}
401431

0 commit comments

Comments
 (0)