android, ios: Pass log level from env in JSON config to Android and iOS (#2756)

- Add `LOG_LEVEL_STATUS_GO` feature flag for a differentiated log level in status-go.
- Remove superfluous `DEBUG_LOGS_ENABLED` feature flag.
- Enable info-level logging for Jenkins and dev builds.

Signed-off-by: andytudhope <tuddy0525@gmail.com>
This commit is contained in:
Pedro Pombeiro 2017-12-22 22:49:58 +01:00 committed by andytudhope
parent 01d993c32e
commit 96ff13a4df
No known key found for this signature in database
GPG Key ID: 02A3DFA93BF26AD2
9 changed files with 31 additions and 16 deletions

2
.env
View File

@ -1,10 +1,10 @@
TESTFAIRY_ENABLED=0
NOTIFICATIONS_WIP_ENABLED=1
DEBUG_LOGS_ENABLED=1
STUB_STATUS_GO=0
ETHEREUM_DEV_CLUSTER=1
MAINNET_NETWORKS_ENABLED=1
ERC20_ENABLED=1
OFFLINE_INBOX_ENABLED=1
LOG_LEVEL=debug
LOG_LEVEL_STATUS_GO=info
JSC_ENABLED=1

View File

@ -1,10 +1,10 @@
TESTFAIRY_ENABLED=1
NOTIFICATIONS_WIP_ENABLED=1
DEBUG_LOGS_ENABLED=1
STUB_STATUS_GO=0
ETHEREUM_DEV_CLUSTER=1
MAINNET_NETWORKS_ENABLED=1
ERC20_ENABLED=1
OFFLINE_INBOX_ENABLED=1
LOG_LEVEL=debug
LOG_LEVEL_STATUS_GO=info
JSC_ENABLED=0

View File

@ -1,10 +1,10 @@
TESTFAIRY_ENABLED=0
NOTIFICATIONS_WIP_ENABLED=1
DEBUG_LOGS_ENABLED=0
STUB_STATUS_GO=0
ETHEREUM_DEV_CLUSTER=0
MAINNET_NETWORKS_ENABLED=0
ERC20_ENABLED=0
OFFLINE_INBOX_ENABLED=0
LOG_LEVEL=info
LOG_LEVEL_STATUS_GO=
JSC_ENABLED=0

View File

@ -25,12 +25,12 @@ node ('macos1') {
// sh 'cp .env.jenkins .env'
sh 'echo TESTFAIRY_ENABLED=' + TESTFAIRY_ENABLED + '>>' + '.env'
sh 'echo NOTIFICATIONS_WIP_ENABLED=' + NOTIFICATIONS_WIP_ENABLED + '>>' + '.env'
sh 'echo DEBUG_LOGS_ENABLED=' + DEBUG_LOGS_ENABLED + '>>' + '.env'
sh 'echo STUB_STATUS_GO=' + STUB_STATUS_GO + '>>' + '.env'
sh 'echo ETHEREUM_DEV_CLUSTER=' + ETHEREUM_DEV_CLUSTER + '>>' + '.env'
sh 'echo MAINNET_NETWORKS_ENABLED=' + MAINNET_NETWORKS_ENABLED + '>>' + '.env'
sh 'echo ERC20_ENABLED=' + ERC20_ENABLED + '>>' + '.env'
sh 'echo LOG_LEVEL=' + LOG_LEVEL + '>>' + '.env'
sh 'echo LOG_LEVEL_STATUS_GO=' + LOG_LEVEL_STATUS_GO + '>>' + '.env'
sh 'echo JSC_ENABLED=' + JSC_ENABLED + '>>' + '.env'
sh 'echo OFFLINE_INBOX_ENABLED=' + OFFLINE_INBOX_ENABLED + '>>' + '.env'

View File

@ -55,7 +55,7 @@ public class MainApplication extends MultiDexApplication implements ReactApplica
jscEnabled = true;
}
StatusPackage statusPackage = new StatusPackage(BuildConfig.DEBUG, devCluster, jscEnabled);
StatusPackage statusPackage = new StatusPackage(BuildConfig.DEBUG, devCluster, jscEnabled, BuildConfig.LOG_LEVEL_STATUS_GO);
Function<String, String> callRPC = statusPackage.getCallRPC();
List<ReactPackage> packages = new ArrayList<ReactPackage>(Arrays.asList(
new MainReactPackage(),

View File

@ -65,10 +65,19 @@ RCTLogFunction RCTTestFairyLogFunction = ^(
signal(SIGPIPE, SIG_IGN);
NSURL *jsCodeLocation;
/* Enable debug logs from React Native for release mode */
NSString *debugLogsEnabled = [ReactNativeConfig envFor:@"DEBUG_LOGS_ENABLED"];
if([debugLogsEnabled isEqualToString:@"1"]){
RCTSetLogThreshold(RCTLogLevelInfo - 1);
/* Set logging level from React Native */
NSString *logLevel = [ReactNativeConfig envFor:@"LOG_LEVEL"];
if([logLevel isEqualToString:@"error"]){
RCTSetLogThreshold(RCTLogLevelError);
}
else if([logLevel isEqualToString:@"warn"]){
RCTSetLogThreshold(RCTLogLevelWarning);
}
else if([logLevel isEqualToString:@"info"]){
RCTSetLogThreshold(RCTLogLevelInfo);
}
else if([logLevel isEqualToString:@"debug"]){
RCTSetLogThreshold(RCTLogLevelTrace);
RCTSetLogFunction(RCTTestFairyLogFunction);
}

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import android.net.Uri;
import android.os.*;
import android.view.WindowManager;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@ -39,15 +40,17 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private ExecutorService executor = null;
private boolean debug;
private boolean devCluster;
private String logLevel;
private Jail jail;
StatusModule(ReactApplicationContext reactContext, boolean debug, boolean devCluster, boolean jscEnabled) {
StatusModule(ReactApplicationContext reactContext, boolean debug, boolean devCluster, boolean jscEnabled, String logLevel) {
super(reactContext);
if (executor == null) {
executor = Executors.newCachedThreadPool();
}
this.debug = debug;
this.devCluster = devCluster;
this.logLevel = logLevel;
reactContext.addLifecycleEventListener(this);
if(jscEnabled) {
jail = new JSCJail(this);
@ -177,9 +180,9 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
JSONObject customConfig = new JSONObject(defaultConfig);
JSONObject jsonConfig = new JSONObject(config);
String gethLogFileName = "geth.log";
jsonConfig.put("LogEnabled", false);
jsonConfig.put("LogEnabled", !TextUtils.isEmpty(this.logLevel));
jsonConfig.put("LogFile", gethLogFileName);
jsonConfig.put("LogLevel", "INFO");
jsonConfig.put("LogLevel", this.logLevel.toUpperCase());
jsonConfig.put("DataDir", root + customConfig.get("DataDir"));
jsonConfig.put("NetworkId", customConfig.get("NetworkId"));
try {

View File

@ -17,11 +17,13 @@ public class StatusPackage implements ReactPackage {
private boolean debug;
private boolean devCluster;
private boolean jscEnabled;
private String logLevel;
public StatusPackage (boolean debug, boolean devCluster, boolean jscEnabled) {
public StatusPackage (boolean debug, boolean devCluster, boolean jscEnabled, String logLevel) {
this.debug = debug;
this.devCluster = devCluster;
this.jscEnabled = jscEnabled;
this.logLevel = logLevel;
}
@Override
@ -29,7 +31,7 @@ public class StatusPackage implements ReactPackage {
List<NativeModule> modules = new ArrayList<>();
System.loadLibrary("statusgoraw");
System.loadLibrary("statusgo");
modules.add(new StatusModule(reactContext, this.debug, this.devCluster, this.jscEnabled));
modules.add(new StatusModule(reactContext, this.debug, this.devCluster, this.jscEnabled, this.logLevel));
return modules;
}

View File

@ -189,6 +189,7 @@ RCT_EXPORT_METHOD(startNode:(NSString *)configString) {
NSString *upstreamURL = [configJSON valueForKeyPath:@"UpstreamConfig.URL"];
NSString *networkDir = [rootUrl.path stringByAppendingString:dataDir];
NSString *devCluster = [ReactNativeConfig envFor:@"ETHEREUM_DEV_CLUSTER"];
NSString *logLevel = [[ReactNativeConfig envFor:@"LOG_LEVEL_STATUS_GO"] uppercaseString];
int dev = 0;
if([devCluster isEqualToString:@"1"]){
dev = 1;
@ -200,9 +201,9 @@ RCT_EXPORT_METHOD(startNode:(NSString *)configString) {
NSURL *networkDirUrl = [NSURL fileURLWithPath:networkDir];
NSURL *logUrl = [networkDirUrl URLByAppendingPathComponent:@"geth.log"];
[resultingConfigJson setValue:newKeystoreUrl.path forKey:@"KeyStoreDir"];
[resultingConfigJson setValue:[NSNumber numberWithBool:YES] forKey:@"LogEnabled"];
[resultingConfigJson setValue:[NSNumber numberWithBool:[logLevel length] != 0] forKey:@"LogEnabled"];
[resultingConfigJson setValue:logUrl.path forKey:@"LogFile"];
[resultingConfigJson setValue:@"DEBUG" forKey:@"LogLevel"];
[resultingConfigJson setValue:logLevel forKey:@"LogLevel"];
if(upstreamURL != nil) {
[resultingConfigJson setValue:[NSNumber numberWithBool:YES] forKeyPath:@"UpstreamConfig.Enabled"];