Skip to content

Commit 0d0a519

Browse files
ryanwilsonpaulb777
authored andcommitted
Remove duplicate logging issue. (firebase#279)
Some combinations of iOS version, simulator/device, and Xcode version result in duplicate logs. This should remove duplicate logs while ensuring that all Firebase related logs are still shown.
1 parent 4d988cc commit 0d0a519

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Firebase/Core/FIRLogger.m

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,22 @@
7777

7878
void FIRLoggerInitializeASL() {
7979
dispatch_once(&sFIRLoggerOnceToken, ^{
80+
NSInteger majorOSVersion = [[FIRAppEnvironmentUtil systemVersion] integerValue];
81+
uint32_t aslOptions = ASL_OPT_STDERR;
82+
#if TARGET_OS_SIMULATOR
83+
// The iOS 11 simulator doesn't need the ASL_OPT_STDERR flag.
84+
if (majorOSVersion >= 11) {
85+
aslOptions = 0;
86+
}
87+
#else
88+
// Devices running iOS 10 or higher don't need the ASL_OPT_STDERR flag.
89+
if (majorOSVersion >= 10) {
90+
aslOptions = 0;
91+
}
92+
#endif // TARGET_OS_SIMULATOR
93+
8094
// Initialize the ASL client handle.
81-
sFIRLoggerClient = asl_open(NULL, kFIRLoggerASLClientFacilityName, ASL_OPT_STDERR);
95+
sFIRLoggerClient = asl_open(NULL, kFIRLoggerASLClientFacilityName, aslOptions);
8296

8397
// Set the filter used by system/device log. Initialize in default mode.
8498
asl_set_filter(sFIRLoggerClient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE));
@@ -104,11 +118,15 @@ void FIRLoggerInitializeASL() {
104118
sFIRLoggerDebugMode = NO;
105119
}
106120

107-
// Need to call asl_add_output_file so that the logs can appear in Xcode's console view. Set
108-
// the ASL filter mask for this output file up to debug level so that all messages are
109-
// viewable in the console.
110-
asl_add_output_file(sFIRLoggerClient, STDERR_FILENO, kFIRLoggerCustomASLMessageFormat,
111-
ASL_TIME_FMT_LCL, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG), ASL_ENCODE_SAFE);
121+
#if TARGET_OS_SIMULATOR
122+
// Need to call asl_add_output_file so that the logs can appear in Xcode's console view when
123+
// running iOS 7. Set the ASL filter mask for this output file up to debug level so that all
124+
// messages are viewable in the console.
125+
if (majorOSVersion == 7) {
126+
asl_add_output_file(sFIRLoggerClient, STDERR_FILENO, kFIRLoggerCustomASLMessageFormat,
127+
ASL_TIME_FMT_LCL, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG), ASL_ENCODE_SAFE);
128+
}
129+
#endif // TARGET_OS_SIMULATOR
112130

113131
sFIRClientQueue = dispatch_queue_create("FIRLoggingClientQueue", DISPATCH_QUEUE_SERIAL);
114132
dispatch_set_target_queue(sFIRClientQueue,

0 commit comments

Comments
 (0)