From f45f96975e5a64b8f2378ce455989ea2cbff6690 Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 29 Nov 2024 22:01:27 +0800 Subject: [PATCH] refactor_: rename LOG_REQUEST_GO to API_LOGGING_ENABLED (#21677) https://github.com/status-im/status-go/compare/032eb5b6...c014fbfc - Rename LOG_REQUEST_GO env variable to API_LOGGING_ENABLED across all env files - Rename requests.log to api.log for consistency - Remove standalone initLogging functionality from native modules as it's now handled within InitializeApplication - Add logging configuration (logEnabled, logLevel, apiLoggingEnabled) to InitializeApplication params - Add logDir parameter for Android to ensure proper log file location This change consolidates logging initialization into the InitializeApplication flow and makes the naming more consistent with its actual functionality. --- .env | 2 +- .env.e2e | 2 +- .env.jenkins | 2 +- .env.nightly | 2 +- .env.release | 2 +- doc/use-status-backend-server.md | 2 +- .../status/ethereum/module/AccountManager.kt | 8 +++- .../im/status/ethereum/module/LogManager.kt | 21 +-------- .../ios/RCTStatus/LogManager.m | 41 +--------------- modules/react-native-status/nodejs/status.cpp | 30 ------------ src/native_module/core.cljs | 4 -- src/status_im/common/log.cljs | 47 +++++++------------ src/status_im/config.cljs | 2 +- src/status_im/contexts/profile/events.cljs | 6 ++- src/tests/test_utils.cljs | 10 +--- status-go-version.json | 6 +-- test/appium/tests/base_test_case.py | 2 +- 17 files changed, 42 insertions(+), 147 deletions(-) diff --git a/.env b/.env index 6d0b13235b..d2afc6525f 100644 --- a/.env +++ b/.env @@ -35,4 +35,4 @@ TEST_NETWORKS_ENABLED=1 SHOW_NOT_IMPLEMENTED_FEATURES=0 ENABLE_ALERT_BANNER=0 FLAG_WALLET_CONNECT_ENABLED=1 -LOG_REQUEST_GO=1 +API_LOGGING_ENABLED=1 diff --git a/.env.e2e b/.env.e2e index 4a858be42a..54454a0a81 100644 --- a/.env.e2e +++ b/.env.e2e @@ -39,4 +39,4 @@ DELETE_MESSAGE_UNDO_TIME_LIMIT=10000 ENABLE_ALERT_BANNER=0 FLAG_WALLET_CONNECT_ENABLED=1 MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0 -LOG_REQUEST_GO=1 +API_LOGGING_ENABLED=1 diff --git a/.env.jenkins b/.env.jenkins index 5c48e90021..041440679d 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -36,4 +36,4 @@ FAST_CREATE_COMMUNITY_ENABLED=1 TEST_NETWORKS_ENABLED=1 ENABLE_ALERT_BANNER=1 FLAG_WALLET_CONNECT_ENABLED=1 -LOG_REQUEST_GO=1 +API_LOGGING_ENABLED=1 diff --git a/.env.nightly b/.env.nightly index e4c4366583..e63c879111 100644 --- a/.env.nightly +++ b/.env.nightly @@ -23,4 +23,4 @@ FAST_CREATE_COMMUNITY_ENABLED=0 TEST_NETWORKS_ENABLED=0 ENABLE_ALERT_BANNER=1 FLAG_WALLET_CONNECT_ENABLED=1 -LOG_REQUEST_GO=0 +API_LOGGING_ENABLED=0 diff --git a/.env.release b/.env.release index 9909342a71..c34df0d0ee 100644 --- a/.env.release +++ b/.env.release @@ -20,4 +20,4 @@ FAST_CREATE_COMMUNITY_ENABLED=0 TEST_NETWORKS_ENABLED=0 STATUS_PROXY_STAGE_NAME=prod FLAG_WALLET_CONNECT_ENABLED=1 -LOG_REQUEST_GO=0 +API_LOGGING_ENABLED=0 diff --git a/doc/use-status-backend-server.md b/doc/use-status-backend-server.md index 32ae06630b..db297aa9a3 100644 --- a/doc/use-status-backend-server.md +++ b/doc/use-status-backend-server.md @@ -26,7 +26,7 @@ export STATUS_BACKEND_SERVER_HOST="127.0.0.1:60000" export STATUS_BACKEND_SERVER_ROOT_DATA_DIR="/path/to/your/root/data/dir" ``` You need to change `STATUS_BACKEND_SERVER_ROOT_DATA_DIR` to your preferred directory and ensure it exists, it should be in absolute path. -All the db files and log files(requests.log/geth.log) and keystore files etc will be stored in this directory. +All the db files and log files(api.log/geth.log) and keystore files etc will be stored in this directory. ### Start the status backend server: ```shell diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt index 0a0bf47ce3..df8cd65f2d 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt @@ -248,10 +248,14 @@ class AccountManager(private val reactContext: ReactApplicationContext) : ReactC @ReactMethod private fun initializeApplication(request: String, callback: Callback) { Log.d(TAG, "initializeApplication") + val jsonParams = JSONObject(request) + // for ios, the log dir will be the same as the root data dir, status-go will default to root data dir if logDir is not provided + jsonParams.put("logDir", utils.getPublicStorageDirectory()?.absolutePath) + val jsonString = jsonParams.toString() StatusBackendClient.executeStatusGoRequestWithCallback( "InitializeApplication", - request, - { Statusgo.initializeApplication(request) }, + jsonString, + { Statusgo.initializeApplication(jsonString) }, callback ) } diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/LogManager.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/LogManager.kt index 69bb36d737..7930b9c853 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/LogManager.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/LogManager.kt @@ -195,25 +195,6 @@ class LogManager(private val reactContext: ReactApplicationContext) : ReactConte } } - @ReactMethod - fun initLogging(enabled: Boolean, mobileSystem: Boolean, logLevel: String, logRequestGo: Boolean, callback: Callback) { - val jsonConfig = JSONObject().apply { - put("Enabled", enabled) - put("MobileSystem", mobileSystem) - put("Level", logLevel) - put("File", getGethLogFile().absolutePath) - put("LogRequestGo", logRequestGo) - put("LogRequestFile", getRequestLogFile().absolutePath) - } - val config = jsonConfig.toString() - StatusBackendClient.executeStatusGoRequestWithCallback( - endpoint = "InitLogging", - requestBody = config, - statusgoFunction = { Statusgo.initLogging(config) }, - callback = callback - ) - } - @ReactMethod(isBlockingSynchronousMethod = true) fun logFileDirectory(): String? { return utils.getPublicStorageDirectory()?.absolutePath @@ -223,7 +204,7 @@ class LogManager(private val reactContext: ReactApplicationContext) : ReactConte private const val TAG = "LogManager" private const val gethLogFileName = "geth.log" private const val statusLogFileName = "Status.log" - private const val requestsLogFileName = "requests.log" + private const val requestsLogFileName = "api.log" private const val logsZipFileName = "Status-debug-logs.zip" } } diff --git a/modules/react-native-status/ios/RCTStatus/LogManager.m b/modules/react-native-status/ios/RCTStatus/LogManager.m index 99ffa9eb00..8fb2b9e0e3 100644 --- a/modules/react-native-status/ios/RCTStatus/LogManager.m +++ b/modules/react-native-status/ios/RCTStatus/LogManager.m @@ -36,7 +36,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson NSURL *mainGethLogsFile = [rootUrl URLByAppendingPathComponent:@"geth.log"]; NSURL *mainLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"]; - NSURL *requestsLogFile = [rootUrl URLByAppendingPathComponent:@"requests.log"]; + NSURL *requestsLogFile = [rootUrl URLByAppendingPathComponent:@"api.log"]; [dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; [jsLogs writeToFile:jsLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil]; @@ -44,7 +44,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson [fileManager copyItemAtPath:mainGethLogsFile.path toPath:mainLogsFile.path error:nil]; if ([fileManager fileExistsAtPath:requestsLogFile.path]) { - [fileManager copyItemAtPath:requestsLogFile.path toPath:[logsFolderName URLByAppendingPathComponent:@"requests.log"].path error:nil]; + [fileManager copyItemAtPath:requestsLogFile.path toPath:[logsFolderName URLByAppendingPathComponent:@"api.log"].path error:nil]; } [SSZipArchive createZipFileAtPath:zipFile.path withContentsOfDirectory:logsFolderName.path]; @@ -53,43 +53,6 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson callback(@[zipFile.absoluteString]); } -RCT_EXPORT_METHOD(initLogging:(BOOL)enabled - mobileSystem:(BOOL)mobileSystem - logLevel:(NSString *)logLevel - logRequestGo:(BOOL)logRequestGo - callback:(RCTResponseSenderBlock)callback) -{ - NSString *logDirectory = [self logFileDirectory]; - NSString *logFilePath = [logDirectory stringByAppendingPathComponent:@"geth.log"]; - NSString *logRequestFilePath = [logDirectory stringByAppendingPathComponent:@"requests.log"]; - - NSDictionary *config = @{ - @"Enabled": @(enabled), - @"MobileSystem": @(mobileSystem), - @"Level": logLevel, - @"File": logFilePath, - @"LogRequestGo": @(logRequestGo), - @"LogRequestFile": logRequestFilePath - }; - - NSError *error; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:config options:0 error:&error]; - - if (error) { - NSLog(@"Error creating JSON: %@", [error localizedDescription]); - return; - } - - NSString *configJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; - - [StatusBackendClient executeStatusGoRequestWithCallback:@"InitLogging" - body:configJson - statusgoFunction:^NSString *{ - return StatusgoInitLogging(configJson); - } - callback:callback]; -} - RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(logFileDirectory) { NSURL *rootUrl = [Utils getRootUrl]; return rootUrl.path; diff --git a/modules/react-native-status/nodejs/status.cpp b/modules/react-native-status/nodejs/status.cpp index 7d9f371aca..7dd2f5747b 100644 --- a/modules/react-native-status/nodejs/status.cpp +++ b/modules/react-native-status/nodejs/status.cpp @@ -1946,35 +1946,6 @@ void _ConnectionChange(const FunctionCallbackInfo& args) { ConnectionChange(arg0, arg1); } -void _InitLogging(const FunctionCallbackInfo& args) { - Isolate* isolate = args.GetIsolate(); - Local context = isolate->GetCurrentContext(); - - if (args.Length() != 1) { - // Throw an Error that is passed back to JavaScript - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8Literal(isolate, "Wrong number of arguments for InitLogging"))); - return; - } - - // Check the argument types - if (!args[0]->IsString()) { - isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8Literal(isolate, "Wrong argument type for 'logSettingsJSON'"))); - return; - } - - String::Utf8Value arg0Obj(isolate, args[0]->ToString(context).ToLocalChecked()); - char *arg0 = *arg0Obj; - - // Call exported Go function, which returns a C string - char *c = InitLogging(arg0); - - Local ret = String::NewFromUtf8(isolate, c).ToLocalChecked(); - args.GetReturnValue().Set(ret); - delete c; -} - void _RestoreAccountAndLogin(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); @@ -2064,7 +2035,6 @@ void init(Local exports) { NODE_SET_METHOD(exports, "hashTransaction", _HashTransaction); NODE_SET_METHOD(exports, "connectionChange", _ConnectionChange); NODE_SET_METHOD(exports, "pollSignal", _PollSignal); - NODE_SET_METHOD(exports, "initLogging", _InitLogging); NODE_SET_METHOD(exports, "restoreAccountAndLogin", _RestoreAccountAndLogin); } diff --git a/src/native_module/core.cljs b/src/native_module/core.cljs index eb5be90c6d..fc1f3a4ee8 100644 --- a/src/native_module/core.cljs +++ b/src/native_module/core.cljs @@ -535,10 +535,6 @@ [] (.logFileDirectory ^js (log-manager))) -(defn init-status-go-logging - [{:keys [enable? mobile-system? log-level log-request-go? callback]}] - (.initLogging ^js (log-manager) enable? mobile-system? log-level log-request-go? callback)) - (defn get-random-mnemonic [callback] (.getRandomMnemonic ^js (account-manager) #(callback (types/json->clj %)))) diff --git a/src/status_im/common/log.cljs b/src/status_im/common/log.cljs index 27b753bcfa..f887ba70bb 100644 --- a/src/status_im/common/log.cljs +++ b/src/status_im/common/log.cljs @@ -2,11 +2,8 @@ (:require [clojure.pprint :as pprint] [clojure.string :as string] - [native-module.core :as native-module] [re-frame.core :as re-frame] - [status-im.config :as config] - [taoensso.timbre :as log] - [utils.transforms :as transforms])) + [taoensso.timbre :as log])) (def logs-queue (atom #queue [])) (def max-log-entries 1000) @@ -21,33 +18,21 @@ (defn setup [level] - (let [handle-error (fn [res] - (let [{:keys [error]} (transforms/json->clj res)] - (when-not (string/blank? error) - (log/error "init statusgo logging failed" error)))) - logging-params {:enable? true - :mobile-system? false - :log-level level - :log-request-go? config/log-request-go - :callback handle-error}] - (log/merge-config! {:ns-filter {:allow #{"*"} :deny #{"taoensso.sente"}}}) - (if (string/blank? level) - (native-module/init-status-go-logging (merge logging-params {:log-level "WARN"})) - (do - (log/set-min-level! (-> level - string/lower-case - keyword)) - (log/merge-config! - {:output-fn (fn [& data] - (let [res (apply log/default-output-fn data)] - (add-log-entry res) - res)) - :middleware [(fn [data] - (update data - :vargs - (partial mapv - #(if (string? %) % (with-out-str (pprint/pprint %))))))]}) - (native-module/init-status-go-logging logging-params))))) + (log/merge-config! {:ns-filter {:allow #{"*"} :deny #{"taoensso.sente"}}}) + (when-not (string/blank? level) + (log/set-min-level! (-> level + string/lower-case + keyword)) + (log/merge-config! + {:output-fn (fn [& data] + (let [res (apply log/default-output-fn data)] + (add-log-entry res) + res)) + :middleware [(fn [data] + (update data + :vargs + (partial mapv + #(if (string? %) % (with-out-str (pprint/pprint %))))))]}))) (re-frame/reg-fx :logs/set-level diff --git a/src/status_im/config.cljs b/src/status_im/config.cljs index 3ccdf9480e..a33e204121 100644 --- a/src/status_im/config.cljs +++ b/src/status_im/config.cljs @@ -71,7 +71,7 @@ ;; CONFIG VALUES (def log-level (string/upper-case (get-config :LOG_LEVEL ""))) -(def log-request-go (enabled? (get-config :LOG_REQUEST_GO "0"))) +(def api-logging-enabled? (enabled? (get-config :API_LOGGING_ENABLED "0"))) (def fleet (get-config :FLEET "")) (def apn-topic (get-config :APN_TOPIC "im.status.ethereum")) (def max-installations 2) diff --git a/src/status_im/contexts/profile/events.cljs b/src/status_im/contexts/profile/events.cljs index af1e6c3a5d..0b32c07fb3 100644 --- a/src/status_im/contexts/profile/events.cljs +++ b/src/status_im/contexts/profile/events.cljs @@ -1,5 +1,6 @@ (ns status-im.contexts.profile.events (:require + [clojure.string :as string] [legacy.status-im.data-store.settings :as data-store.settings] [legacy.status-im.multiaccounts.update.core :as multiaccounts.update] [native-module.core :as native-module] @@ -36,7 +37,10 @@ {:dataDir (native-module/backup-disabled-data-dir) :mixpanelAppId config/mixpanel-app-id :mixpanelToken config/mixpanel-token - :mediaServerEnableTLS (config/enabled? config/STATUS_BACKEND_SERVER_MEDIA_SERVER_ENABLE_TLS)} + :mediaServerEnableTLS (config/enabled? config/STATUS_BACKEND_SERVER_MEDIA_SERVER_ENABLE_TLS) + :logEnabled (not (string/blank? config/log-level)) + :logLevel config/log-level + :apiLoggingEnabled config/api-logging-enabled?} callback))) (rf/reg-event-fx diff --git a/src/tests/test_utils.cljs b/src/tests/test_utils.cljs index 833d2e2c1d..e1aa16c865 100644 --- a/src/tests/test_utils.cljs +++ b/src/tests/test_utils.cljs @@ -116,15 +116,7 @@ (def log-manager (clj->js {:logFileDirectory - (fn [] (str test-dir "/log")) - :initLogging - (fn [enabled mobile-system log-level log-request-go? callback] - (callback (.initLogging native-status - (types/clj->json {:Enabled enabled - :MobileSystem mobile-system - :Level log-level - :LogRequestGo log-request-go? - :LogRequestFile (str test-dir "/request.log")}))))})) + (fn [] (str test-dir "/log"))})) (def network (clj->js diff --git a/status-go-version.json b/status-go-version.json index 86c82cedaf..47fc7526ad 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v6.0.0", - "commit-sha1": "83ea49fc04cd521864a64fd2d94d4e5309a81645", - "src-sha256": "0f93s1yr8p24aw9ji5wsmq07vf4599nk4bhr55q0ifx0szhabilx" + "version": "v6.1.0", + "commit-sha1": "c014fbfc1ec739aad2db951fdcff6182d4dbd919", + "src-sha256": "16im0nc8zri5z1wvzbh83331g02iy305m2lca4ljjgdmlaq6l2zx" } diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 7cc9aef48d..bc9e016368 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -117,7 +117,7 @@ def pull_geth(driver): def pull_requests_log(driver): - result = driver.pull_file(get_app_path() + 'requests.log') + result = driver.pull_file(get_app_path() + 'api.log') return base64.b64decode(result)