fix geth.log on Android

This commit is contained in:
Roman Volosovskyi 2018-01-17 20:38:09 +02:00
parent c5bea68fdc
commit 6c72b6d5db
No known key found for this signature in database
GPG Key ID: 37135489EAE4B2D7
1 changed files with 39 additions and 24 deletions

View File

@ -114,6 +114,38 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
this.getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params);
}
private String prepareLogsFile() {
String gethLogFileName = "geth.log";
File pubDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File logFile = new File(pubDirectory, gethLogFileName);
try {
logFile.setReadable(true);
File parent = logFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
logFile.createNewFile();
logFile.setReadable(true);
Uri gethLogUri = Uri.fromFile(logFile);
try {
Log.d(TAG, "Attach to geth.log to instabug " + gethLogUri.getPath());
Instabug.setFileAttachment(gethLogUri, gethLogFileName);
} catch (NullPointerException e) {
Log.d(TAG, "Instabug is not initialized!");
}
String gethLogFilePath = logFile.getAbsolutePath();
Log.d("ExtDirLog", gethLogFilePath);
return gethLogFilePath;
} catch (Exception e) {
Log.d(TAG, "Can't create geth.log file! " + e.getMessage());
}
return null;
}
private void doStartNode(final String defaultConfig) {
Activity currentActivity = getCurrentActivity();
@ -179,11 +211,14 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
try {
JSONObject customConfig = new JSONObject(defaultConfig);
JSONObject jsonConfig = new JSONObject(config);
String gethLogFileName = "geth.log";
jsonConfig.put("LogEnabled", !TextUtils.isEmpty(this.logLevel));
jsonConfig.put("LogFile", gethLogFileName);
String gethLogFilePath = prepareLogsFile();
boolean logsEnabled = (gethLogFilePath != null) && !TextUtils.isEmpty(this.logLevel);
String dataDir = root + customConfig.get("DataDir");
jsonConfig.put("LogEnabled", logsEnabled);
jsonConfig.put("LogFile", gethLogFilePath);
jsonConfig.put("LogLevel", TextUtils.isEmpty(this.logLevel) ? "ERROR" : this.logLevel.toUpperCase());
jsonConfig.put("DataDir", root + customConfig.get("DataDir"));
jsonConfig.put("DataDir", dataDir);
jsonConfig.put("NetworkId", customConfig.get("NetworkId"));
try {
Object upstreamConfig = customConfig.get("UpstreamConfig");
@ -195,26 +230,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
jsonConfig.put("KeyStoreDir", newKeystoreDir);
String gethLogPath = dataFolder + "/" + gethLogFileName;
File logFile = new File(gethLogPath);
try {
logFile.setReadable(true);
File parent = logFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
logFile.createNewFile();
logFile.setReadable(true);
} catch (Exception e) {
Log.d(TAG, "Can't create geth.log file!");
}
Uri gethLogUri = Uri.fromFile(logFile);
try {
Log.d(TAG, "Attach to geth.log to instabug " + gethLogUri.getPath());
Instabug.setFileAttachment(gethLogUri, gethLogFileName);
} catch (NullPointerException e) {
Log.d(TAG, "Instabug is not initialized!");
}
config = jsonConfig.toString();
} catch (JSONException e) {