[android][database] add enableLogging warning messages if called after db usage
This commit is contained in:
parent
961112a108
commit
66a550b755
@ -1,6 +1,7 @@
|
|||||||
package io.invertase.firebase.database;
|
package io.invertase.firebase.database;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.facebook.react.bridge.Promise;
|
import com.facebook.react.bridge.Promise;
|
||||||
@ -92,11 +93,18 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
|
|||||||
List<FirebaseApp> firebaseAppList = FirebaseApp.getApps(getReactApplicationContext());
|
List<FirebaseApp> firebaseAppList = FirebaseApp.getApps(getReactApplicationContext());
|
||||||
for (FirebaseApp app : firebaseAppList) {
|
for (FirebaseApp app : firebaseAppList) {
|
||||||
loggingLevelSet.put(app.getName(), enabled);
|
loggingLevelSet.put(app.getName(), enabled);
|
||||||
|
try {
|
||||||
if (enableLogging) {
|
if (enableLogging) {
|
||||||
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.DEBUG);
|
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.DEBUG);
|
||||||
} else {
|
} else {
|
||||||
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.WARN);
|
FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.WARN);
|
||||||
|
}
|
||||||
|
} catch (DatabaseException dex) {
|
||||||
|
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
|
||||||
|
// only occurs in dev after reloading or if user has actually incorrectly called it.
|
||||||
|
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
|
||||||
|
"If you are sure you've done this then this message can be ignored during development as \n" +
|
||||||
|
"RN reloads can cause false positives. APP: " + app.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -499,6 +507,10 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
|
|||||||
firebaseDatabase.setLogLevel(Logger.Level.DEBUG);
|
firebaseDatabase.setLogLevel(Logger.Level.DEBUG);
|
||||||
} catch (DatabaseException dex) {
|
} catch (DatabaseException dex) {
|
||||||
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
|
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
|
||||||
|
// only occurs in dev after reloading or if user has actually incorrectly called it.
|
||||||
|
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
|
||||||
|
"If you are sure you've done this then this message can be ignored during development as \n" +
|
||||||
|
"RN reloads can cause false positives. APP: " + firebaseDatabase.getApp().getName());
|
||||||
}
|
}
|
||||||
} else if (!enableLogging && (logLevel != null && logLevel)) {
|
} else if (!enableLogging && (logLevel != null && logLevel)) {
|
||||||
try {
|
try {
|
||||||
@ -506,6 +518,10 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
|
|||||||
firebaseDatabase.setLogLevel(Logger.Level.WARN);
|
firebaseDatabase.setLogLevel(Logger.Level.WARN);
|
||||||
} catch (DatabaseException dex) {
|
} catch (DatabaseException dex) {
|
||||||
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
|
// do nothing - to catch 'calls to setLogLevel must be made for use of database' errors
|
||||||
|
// only occurs in dev after reloading or if user has actually incorrectly called it.
|
||||||
|
Log.w(TAG, "WARNING: enableLogging(bool) must be called before any other use of database(). \n" +
|
||||||
|
"If you are sure you've done this then this message can be ignored during development as \n" +
|
||||||
|
"RN reloads can cause false positives. APP: " + firebaseDatabase.getApp().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user