From 3226309bab6a0c92d3da6f492908ee45bd5dc7de Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 30 Apr 2019 14:49:45 +0300 Subject: [PATCH] Add js logs to archive --- .../status/ethereum/module/StatusModule.java | 2 +- .../react-native-status/desktop/rctstatus.cpp | 3 ++- .../react-native-status/desktop/rctstatus.h | 2 +- .../ios/RCTStatus/RCTStatus.m | 23 +++++++++++-------- src/status_im/core.cljs | 6 ++--- src/status_im/native_module/core.cljs | 4 ++-- src/status_im/native_module/impl/module.cljs | 4 ++-- src/status_im/utils/logging/core.cljs | 23 ++++++++++++++++++- 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index 9dfc211129..aec93250df 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -559,7 +559,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL } @ReactMethod - public void sendLogs(final String dbJson, final Callback callback) { + public void sendLogs(final String dbJson, final String jsLogs, final Callback callback) { Log.d(TAG, "sendLogs"); if (!checkAvailability()) { return; diff --git a/modules/react-native-status/desktop/rctstatus.cpp b/modules/react-native-status/desktop/rctstatus.cpp index 2c5b38be22..4aa763e083 100644 --- a/modules/react-native-status/desktop/rctstatus.cpp +++ b/modules/react-native-status/desktop/rctstatus.cpp @@ -201,7 +201,7 @@ void showFileInGraphicalShell(QWidget *parent, const QFileInfo &fileInfo) #endif } -void RCTStatus::sendLogs(QString dbJSON, double callbackId) { +void RCTStatus::sendLogs(QString dbJSON, QString jsLogs, double callbackId) { Q_D(RCTStatus); qCDebug(RCTSTATUS) << "::sendLogs call - logFilePath:" << getLogFilePath() @@ -230,6 +230,7 @@ void RCTStatus::sendLogs(QString dbJSON, double callbackId) { QFile gethLogFile(d_gethLogFilePath); QFile logFile(getLogFilePath()); zipWriter.addFile("db.json", dbJSON.toUtf8()); + zipWriter.addFile("js_logs.log", jsLogs.toUtf8()); if (gethLogFile.exists()) { zipWriter.addFile(QFileInfo(gethLogFile).fileName(), &gethLogFile); } diff --git a/modules/react-native-status/desktop/rctstatus.h b/modules/react-native-status/desktop/rctstatus.h index 3c940ccd8f..a91a67812c 100644 --- a/modules/react-native-status/desktop/rctstatus.h +++ b/modules/react-native-status/desktop/rctstatus.h @@ -39,7 +39,7 @@ public: Q_INVOKABLE void stopNode(); Q_INVOKABLE void createAccount(QString password, double callbackId); Q_INVOKABLE void sendDataNotification(QString dataPayloadJSON, QString tokensJSON, double callbackId); - Q_INVOKABLE void sendLogs(QString dbJSON, double callbackId); + Q_INVOKABLE void sendLogs(QString dbJSON, QString jsLogs, double callbackId); Q_INVOKABLE void addPeer(QString enode, double callbackId); Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId); Q_INVOKABLE void login(QString address, QString password, double callbackId); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 274507ec84..d0d1237324 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -229,6 +229,7 @@ RCT_EXPORT_METHOD(sendDataNotification:(NSString *)dataPayloadJSON #pragma mark - SendLogs method //////////////////////////////////////////////////////////////////// sendLogs RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson + jsLogs:(NSString *)jsLogs callback:(RCTResponseSenderBlock)callback) { // TODO: Implement SendLogs for iOS #if DEBUG @@ -239,35 +240,37 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson NSURL *rootUrl =[[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; - + NSURL *zipFile = [rootUrl URLByAppendingPathComponent:@"logs.zip"]; [fileManager removeItemAtPath:zipFile.path error:nil]; - + NSURL *logsFolderName = [rootUrl URLByAppendingPathComponent:@"logs"]; - + if (![fileManager fileExistsAtPath:logsFolderName.path]) [fileManager createDirectoryAtPath:logsFolderName.path withIntermediateDirectories:YES attributes:nil error:&error]; - + NSURL *dbFile = [logsFolderName URLByAppendingPathComponent:@"db.json"]; + NSURL *jsLogsFile = [logsFolderName URLByAppendingPathComponent:@"Status.log"]; #if DEBUG NSString *networkDirPath = @"ethereum/mainnet_rpc_dev"; #else NSString *networkDirPath = @"ethereum/mainnet_rpc"; #endif - + NSURL *networkDir = [rootUrl URLByAppendingPathComponent:networkDirPath]; NSURL *originalGethLogsFile = [networkDir URLByAppendingPathComponent:@"geth.log"]; NSURL *gethLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"]; - + [dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; - + [jsLogs writeToFile:jsLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; + //NSString* gethLogs = StatusgoExportNodeLogs(); //[gethLogs writeToFile:gethLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; [fileManager copyItemAtPath:originalGethLogsFile.path toPath:gethLogsFile.path error:nil]; - + [SSZipArchive createZipFileAtPath:zipFile.path withContentsOfDirectory:logsFolderName.path]; [fileManager removeItemAtPath:logsFolderName.path error:nil]; - + callback(@[zipFile.path]); } @@ -355,7 +358,7 @@ RCT_EXPORT_METHOD(verify:(NSString *)address URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"]; - + NSString *result = StatusgoVerifyAccountPassword(absKeystoreUrl.path, address, password); callback(@[result]); } diff --git a/src/status_im/core.cljs b/src/status_im/core.cljs index 513793c030..9b57752110 100644 --- a/src/status_im/core.cljs +++ b/src/status_im/core.cljs @@ -7,10 +7,8 @@ [reagent.core :as reagent] status-im.transport.impl.receive status-im.transport.impl.send - [taoensso.timbre :as log] - [status-im.utils.config :as config] [status-im.react-native.js-dependencies :as js-dependencies] - [goog.object :as object] + [status-im.utils.logging.core :as utils.logs] cljs.core.specs.alpha)) (if js/goog.DEBUG @@ -18,7 +16,7 @@ (aset js/console "disableYellowBox" true)) (defn init [app-root] - (log/set-level! config/log-level) + (utils.logs/init-logs) (error-handler/register-exception-handler!) (re-frame/dispatch [:init/app-started]) (.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)) diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index b7e7c47400..8e4d3c78ea 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -70,8 +70,8 @@ (defn send-data-notification [m callback] (native-module/send-data-notification m callback)) -(defn send-logs [dbJson callback] - (native-module/send-logs dbJson callback)) +(defn send-logs [dbJson js-logs callback] + (native-module/send-logs dbJson js-logs callback)) (defn add-peer [enode callback] (native-module/add-peer enode callback)) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 53e85e9f2e..184807bae3 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -49,9 +49,9 @@ (when status (.sendDataNotification status data-payload tokens on-result))) -(defn send-logs [dbJson callback] +(defn send-logs [dbJson js-logs callback] (when status - (.sendLogs status dbJson callback))) + (.sendLogs status dbJson js-logs callback))) (defn add-peer [enode on-result] (when (and @node-started status) diff --git a/src/status_im/utils/logging/core.cljs b/src/status_im/utils/logging/core.cljs index 9589c46024..b6abfe6343 100644 --- a/src/status_im/utils/logging/core.cljs +++ b/src/status_im/utils/logging/core.cljs @@ -4,15 +4,36 @@ [status-im.utils.fx :as fx] [status-im.utils.types :as types] [status-im.utils.handlers :as handlers] - [status-im.utils.email :as mail])) + [status-im.utils.email :as mail] + [taoensso.timbre :as log] + [status-im.utils.config :as config])) (def report-email "error-reports@status.im") +(def max-log-entries 1000) +(def logs-queue (atom #queue[])) +(defn add-log-entry [entry] + (swap! logs-queue conj entry) + (when (>= (count @logs-queue) max-log-entries) + (swap! logs-queue pop))) + +(defn init-logs [] + (log/set-level! config/log-level) + (log/debug) + (log/merge-config! + {:output-fn (fn [& data] + (let [res (apply log/default-output-fn data)] + (add-log-entry res) + res))})) + +(defn get-js-logs [] + (clojure.string/join "\n" @logs-queue)) (re-frame/reg-fx :logs/archive-logs (fn [[db-json callback-handler]] (status/send-logs db-json + (get-js-logs) #(re-frame/dispatch [callback-handler %])))) (fx/defn send-logs