Skip to content

Commit 66a550b

Browse files
committed
[android][database] add enableLogging warning messages if called after db usage
1 parent 961112a commit 66a550b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabase.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.invertase.firebase.database;
22

33
import android.os.AsyncTask;
4+
import android.util.Log;
45
import android.util.SparseArray;
56

67
import com.facebook.react.bridge.Promise;
@@ -92,11 +93,18 @@ public void enableLogging(Boolean enabled) {
9293
List<FirebaseApp> firebaseAppList = FirebaseApp.getApps(getReactApplicationContext());
9394
for (FirebaseApp app : firebaseAppList) {
9495
loggingLevelSet.put(app.getName(), enabled);
95-
96-
if (enableLogging) {
97-
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.DEBUG);
98-
} else {
99-
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.WARN);
96+
try {
97+
if (enableLogging) {
98+
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.DEBUG);
99+
} else {
100+
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.WARN);
101+
}
102+
} catch (DatabaseException dex) {
103+
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
104+
// only occurs in dev after reloading or if user has actually incorrectly called it.
105+
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
106+
"If you are sure you've done this then this message can be ignored during development as \n" +
107+
"RN reloads can cause false positives. APP: " + app.getName());
100108
}
101109
}
102110
}
@@ -499,13 +507,21 @@ private FirebaseDatabase getDatabaseForApp(String appName) {
499507
firebaseDatabase.setLogLevel(Logger.Level.DEBUG);
500508
} catch (DatabaseException dex) {
501509
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
510+
// only occurs in dev after reloading or if user has actually incorrectly called it.
511+
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
512+
"If you are sure you've done this then this message can be ignored during development as \n" +
513+
"RN reloads can cause false positives. APP: " + firebaseDatabase.getApp().getName());
502514
}
503515
} else if (!enableLogging && (logLevel != null && logLevel)) {
504516
try {
505517
loggingLevelSet.put(firebaseDatabase.getApp().getName(), enableLogging);
506518
firebaseDatabase.setLogLevel(Logger.Level.WARN);
507519
} catch (DatabaseException dex) {
508520
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
521+
// only occurs in dev after reloading or if user has actually incorrectly called it.
522+
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
523+
"If you are sure you've done this then this message can be ignored during development as \n" +
524+
"RN reloads can cause false positives. APP: " + firebaseDatabase.getApp().getName());
509525
}
510526
}
511527

0 commit comments

Comments
 (0)