Add js logs to archive

This commit is contained in:
Roman Volosovskyi 2019-04-30 14:49:45 +03:00
parent 713a461415
commit 3226309bab
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 45 additions and 22 deletions

View File

@ -559,7 +559,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
} }
@ReactMethod @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"); Log.d(TAG, "sendLogs");
if (!checkAvailability()) { if (!checkAvailability()) {
return; return;

View File

@ -201,7 +201,7 @@ void showFileInGraphicalShell(QWidget *parent, const QFileInfo &fileInfo)
#endif #endif
} }
void RCTStatus::sendLogs(QString dbJSON, double callbackId) { void RCTStatus::sendLogs(QString dbJSON, QString jsLogs, double callbackId) {
Q_D(RCTStatus); Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::sendLogs call - logFilePath:" << getLogFilePath() qCDebug(RCTSTATUS) << "::sendLogs call - logFilePath:" << getLogFilePath()
@ -230,6 +230,7 @@ void RCTStatus::sendLogs(QString dbJSON, double callbackId) {
QFile gethLogFile(d_gethLogFilePath); QFile gethLogFile(d_gethLogFilePath);
QFile logFile(getLogFilePath()); QFile logFile(getLogFilePath());
zipWriter.addFile("db.json", dbJSON.toUtf8()); zipWriter.addFile("db.json", dbJSON.toUtf8());
zipWriter.addFile("js_logs.log", jsLogs.toUtf8());
if (gethLogFile.exists()) { if (gethLogFile.exists()) {
zipWriter.addFile(QFileInfo(gethLogFile).fileName(), &gethLogFile); zipWriter.addFile(QFileInfo(gethLogFile).fileName(), &gethLogFile);
} }

View File

@ -39,7 +39,7 @@ public:
Q_INVOKABLE void stopNode(); Q_INVOKABLE void stopNode();
Q_INVOKABLE void createAccount(QString password, double callbackId); Q_INVOKABLE void createAccount(QString password, double callbackId);
Q_INVOKABLE void sendDataNotification(QString dataPayloadJSON, QString tokensJSON, 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 addPeer(QString enode, double callbackId);
Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId); Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId);
Q_INVOKABLE void login(QString address, QString password, double callbackId); Q_INVOKABLE void login(QString address, QString password, double callbackId);

View File

@ -229,6 +229,7 @@ RCT_EXPORT_METHOD(sendDataNotification:(NSString *)dataPayloadJSON
#pragma mark - SendLogs method #pragma mark - SendLogs method
//////////////////////////////////////////////////////////////////// sendLogs //////////////////////////////////////////////////////////////////// sendLogs
RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
jsLogs:(NSString *)jsLogs
callback:(RCTResponseSenderBlock)callback) { callback:(RCTResponseSenderBlock)callback) {
// TODO: Implement SendLogs for iOS // TODO: Implement SendLogs for iOS
#if DEBUG #if DEBUG
@ -249,6 +250,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
[fileManager createDirectoryAtPath:logsFolderName.path withIntermediateDirectories:YES attributes:nil error:&error]; [fileManager createDirectoryAtPath:logsFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
NSURL *dbFile = [logsFolderName URLByAppendingPathComponent:@"db.json"]; NSURL *dbFile = [logsFolderName URLByAppendingPathComponent:@"db.json"];
NSURL *jsLogsFile = [logsFolderName URLByAppendingPathComponent:@"Status.log"];
#if DEBUG #if DEBUG
NSString *networkDirPath = @"ethereum/mainnet_rpc_dev"; NSString *networkDirPath = @"ethereum/mainnet_rpc_dev";
#else #else
@ -260,6 +262,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
NSURL *gethLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"]; NSURL *gethLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"];
[dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; [dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
[jsLogs writeToFile:jsLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
//NSString* gethLogs = StatusgoExportNodeLogs(); //NSString* gethLogs = StatusgoExportNodeLogs();
//[gethLogs writeToFile:gethLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; //[gethLogs writeToFile:gethLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];

View File

@ -7,10 +7,8 @@
[reagent.core :as reagent] [reagent.core :as reagent]
status-im.transport.impl.receive status-im.transport.impl.receive
status-im.transport.impl.send status-im.transport.impl.send
[taoensso.timbre :as log]
[status-im.utils.config :as config]
[status-im.react-native.js-dependencies :as js-dependencies] [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)) cljs.core.specs.alpha))
(if js/goog.DEBUG (if js/goog.DEBUG
@ -18,7 +16,7 @@
(aset js/console "disableYellowBox" true)) (aset js/console "disableYellowBox" true))
(defn init [app-root] (defn init [app-root]
(log/set-level! config/log-level) (utils.logs/init-logs)
(error-handler/register-exception-handler!) (error-handler/register-exception-handler!)
(re-frame/dispatch [:init/app-started]) (re-frame/dispatch [:init/app-started])
(.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)) (.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root))

View File

@ -70,8 +70,8 @@
(defn send-data-notification [m callback] (defn send-data-notification [m callback]
(native-module/send-data-notification m callback)) (native-module/send-data-notification m callback))
(defn send-logs [dbJson callback] (defn send-logs [dbJson js-logs callback]
(native-module/send-logs dbJson callback)) (native-module/send-logs dbJson js-logs callback))
(defn add-peer [enode callback] (defn add-peer [enode callback]
(native-module/add-peer enode callback)) (native-module/add-peer enode callback))

View File

@ -49,9 +49,9 @@
(when status (when status
(.sendDataNotification status data-payload tokens on-result))) (.sendDataNotification status data-payload tokens on-result)))
(defn send-logs [dbJson callback] (defn send-logs [dbJson js-logs callback]
(when status (when status
(.sendLogs status dbJson callback))) (.sendLogs status dbJson js-logs callback)))
(defn add-peer [enode on-result] (defn add-peer [enode on-result]
(when (and @node-started status) (when (and @node-started status)

View File

@ -4,15 +4,36 @@
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.handlers :as handlers] [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 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 (re-frame/reg-fx
:logs/archive-logs :logs/archive-logs
(fn [[db-json callback-handler]] (fn [[db-json callback-handler]]
(status/send-logs (status/send-logs
db-json db-json
(get-js-logs)
#(re-frame/dispatch [callback-handler %])))) #(re-frame/dispatch [callback-handler %]))))
(fx/defn send-logs (fx/defn send-logs