|
1 | 1 | package io.invertase.firebase.database;
|
2 | 2 |
|
3 | 3 | import android.os.AsyncTask;
|
| 4 | +import android.util.Log; |
4 | 5 | import android.util.SparseArray;
|
5 | 6 |
|
6 | 7 | import com.facebook.react.bridge.Promise;
|
@@ -92,11 +93,18 @@ public void enableLogging(Boolean enabled) {
|
92 | 93 | List<FirebaseApp> firebaseAppList = FirebaseApp.getApps(getReactApplicationContext());
|
93 | 94 | for (FirebaseApp app : firebaseAppList) {
|
94 | 95 | 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()); |
100 | 108 | }
|
101 | 109 | }
|
102 | 110 | }
|
@@ -499,13 +507,21 @@ private FirebaseDatabase getDatabaseForApp(String appName) {
|
499 | 507 | firebaseDatabase.setLogLevel(Logger.Level.DEBUG);
|
500 | 508 | } catch (DatabaseException dex) {
|
501 | 509 | // 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()); |
502 | 514 | }
|
503 | 515 | } else if (!enableLogging && (logLevel != null && logLevel)) {
|
504 | 516 | try {
|
505 | 517 | loggingLevelSet.put(firebaseDatabase.getApp().getName(), enableLogging);
|
506 | 518 | firebaseDatabase.setLogLevel(Logger.Level.WARN);
|
507 | 519 | } catch (DatabaseException dex) {
|
508 | 520 | // 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()); |
509 | 525 | }
|
510 | 526 | }
|
511 | 527 |
|
|
0 commit comments