@@ -133,6 +133,10 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
133
133
return platform_app;
134
134
}
135
135
136
+ // Settings cached by SetFirConfigurationLoggerLevel if App wasn't already initialized.
137
+ static bool g_delayed_fir_configuration_logger_level_set = false ;
138
+ static FIRLoggerLevel g_delayed_fir_configuration_logger_level = FIRLoggerLevelWarning;
139
+
136
140
// Create an iOS FIRApp instance.
137
141
static FIRApp* CreatePlatformApp (const AppOptions& options, const char * name) {
138
142
__block FIRApp* platform_app = nil ;
@@ -155,6 +159,14 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
155
159
[FIRApp configureWithName: @(name) options: platform_options];
156
160
}
157
161
platform_app = GetPlatformAppByName (name);
162
+ // If the logger level was cached due to logging happening prior to
163
+ // App's initialization, apply the delayed setting now, when FIRApp
164
+ // is guaranteed to exist and we are in the main thread.
165
+ if (g_delayed_fir_configuration_logger_level_set) {
166
+ g_delayed_fir_configuration_logger_level_set = false ;
167
+ [[FIRConfiguration sharedInstance ]
168
+ setLoggerLevel: g_delayed_fir_configuration_logger_level];
169
+ }
158
170
} @catch (NSException * e) {
159
171
LogError (" Unable to configure Firebase app (%s)" ,
160
172
util::NSStringToString (e.reason).c_str());
@@ -276,4 +288,19 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
276
288
277
289
FIRApp* App::GetPlatformApp () const { return internal_->get (); }
278
290
291
+ void SetFirConfigurationLoggerLevel (FIRLoggerLevel level) {
292
+ // Check if a FIRApp has been created. FIRApp.allApps will return a
293
+ // list of all FIRApps, or nil if no FIRApp has been created yet.
294
+ if (FIRApp.allApps != nil ) {
295
+ // FIRApp has already been initialized, it's safe to set this
296
+ // value now.
297
+ [[FIRConfiguration sharedInstance ] setLoggerLevel: level];
298
+ } else {
299
+ // FIRApp has not yet been initialized. Cache this value to set
300
+ // later, in CreatePlatformApp().
301
+ g_delayed_fir_configuration_logger_level = level;
302
+ g_delayed_fir_configuration_logger_level_set = true ;
303
+ }
304
+ }
305
+
279
306
} // namespace firebase
0 commit comments