refactor_: rename LOG_REQUEST_GO to API_LOGGING_ENABLED (#21677)

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.
This commit is contained in:
frank 2024-11-29 22:01:27 +08:00 committed by GitHub
parent 53d5ac4ea2
commit f45f96975e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 42 additions and 147 deletions

2
.env
View File

@ -35,4 +35,4 @@ TEST_NETWORKS_ENABLED=1
SHOW_NOT_IMPLEMENTED_FEATURES=0 SHOW_NOT_IMPLEMENTED_FEATURES=0
ENABLE_ALERT_BANNER=0 ENABLE_ALERT_BANNER=0
FLAG_WALLET_CONNECT_ENABLED=1 FLAG_WALLET_CONNECT_ENABLED=1
LOG_REQUEST_GO=1 API_LOGGING_ENABLED=1

View File

@ -39,4 +39,4 @@ DELETE_MESSAGE_UNDO_TIME_LIMIT=10000
ENABLE_ALERT_BANNER=0 ENABLE_ALERT_BANNER=0
FLAG_WALLET_CONNECT_ENABLED=1 FLAG_WALLET_CONNECT_ENABLED=1
MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0 MOBILE_DATA_SYNCING_TOGGLE_ENABLE=0
LOG_REQUEST_GO=1 API_LOGGING_ENABLED=1

View File

@ -36,4 +36,4 @@ FAST_CREATE_COMMUNITY_ENABLED=1
TEST_NETWORKS_ENABLED=1 TEST_NETWORKS_ENABLED=1
ENABLE_ALERT_BANNER=1 ENABLE_ALERT_BANNER=1
FLAG_WALLET_CONNECT_ENABLED=1 FLAG_WALLET_CONNECT_ENABLED=1
LOG_REQUEST_GO=1 API_LOGGING_ENABLED=1

View File

@ -23,4 +23,4 @@ FAST_CREATE_COMMUNITY_ENABLED=0
TEST_NETWORKS_ENABLED=0 TEST_NETWORKS_ENABLED=0
ENABLE_ALERT_BANNER=1 ENABLE_ALERT_BANNER=1
FLAG_WALLET_CONNECT_ENABLED=1 FLAG_WALLET_CONNECT_ENABLED=1
LOG_REQUEST_GO=0 API_LOGGING_ENABLED=0

View File

@ -20,4 +20,4 @@ FAST_CREATE_COMMUNITY_ENABLED=0
TEST_NETWORKS_ENABLED=0 TEST_NETWORKS_ENABLED=0
STATUS_PROXY_STAGE_NAME=prod STATUS_PROXY_STAGE_NAME=prod
FLAG_WALLET_CONNECT_ENABLED=1 FLAG_WALLET_CONNECT_ENABLED=1
LOG_REQUEST_GO=0 API_LOGGING_ENABLED=0

View File

@ -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" 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. 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: ### Start the status backend server:
```shell ```shell

View File

@ -248,10 +248,14 @@ class AccountManager(private val reactContext: ReactApplicationContext) : ReactC
@ReactMethod @ReactMethod
private fun initializeApplication(request: String, callback: Callback) { private fun initializeApplication(request: String, callback: Callback) {
Log.d(TAG, "initializeApplication") 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( StatusBackendClient.executeStatusGoRequestWithCallback(
"InitializeApplication", "InitializeApplication",
request, jsonString,
{ Statusgo.initializeApplication(request) }, { Statusgo.initializeApplication(jsonString) },
callback callback
) )
} }

View File

@ -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) @ReactMethod(isBlockingSynchronousMethod = true)
fun logFileDirectory(): String? { fun logFileDirectory(): String? {
return utils.getPublicStorageDirectory()?.absolutePath return utils.getPublicStorageDirectory()?.absolutePath
@ -223,7 +204,7 @@ class LogManager(private val reactContext: ReactApplicationContext) : ReactConte
private const val TAG = "LogManager" private const val TAG = "LogManager"
private const val gethLogFileName = "geth.log" private const val gethLogFileName = "geth.log"
private const val statusLogFileName = "Status.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" private const val logsZipFileName = "Status-debug-logs.zip"
} }
} }

View File

@ -36,7 +36,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
NSURL *mainGethLogsFile = [rootUrl URLByAppendingPathComponent:@"geth.log"]; NSURL *mainGethLogsFile = [rootUrl URLByAppendingPathComponent:@"geth.log"];
NSURL *mainLogsFile = [logsFolderName 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]; [dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
[jsLogs writeToFile:jsLogsFile.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]; [fileManager copyItemAtPath:mainGethLogsFile.path toPath:mainLogsFile.path error:nil];
if ([fileManager fileExistsAtPath:requestsLogFile.path]) { 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]; [SSZipArchive createZipFileAtPath:zipFile.path withContentsOfDirectory:logsFolderName.path];
@ -53,43 +53,6 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
callback(@[zipFile.absoluteString]); 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) { RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(logFileDirectory) {
NSURL *rootUrl = [Utils getRootUrl]; NSURL *rootUrl = [Utils getRootUrl];
return rootUrl.path; return rootUrl.path;

View File

@ -1946,35 +1946,6 @@ void _ConnectionChange(const FunctionCallbackInfo<Value>& args) {
ConnectionChange(arg0, arg1); ConnectionChange(arg0, arg1);
} }
void _InitLogging(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> 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<String> ret = String::NewFromUtf8(isolate, c).ToLocalChecked();
args.GetReturnValue().Set(ret);
delete c;
}
void _RestoreAccountAndLogin(const FunctionCallbackInfo<Value>& args) { void _RestoreAccountAndLogin(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext(); Local<Context> context = isolate->GetCurrentContext();
@ -2064,7 +2035,6 @@ void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hashTransaction", _HashTransaction); NODE_SET_METHOD(exports, "hashTransaction", _HashTransaction);
NODE_SET_METHOD(exports, "connectionChange", _ConnectionChange); NODE_SET_METHOD(exports, "connectionChange", _ConnectionChange);
NODE_SET_METHOD(exports, "pollSignal", _PollSignal); NODE_SET_METHOD(exports, "pollSignal", _PollSignal);
NODE_SET_METHOD(exports, "initLogging", _InitLogging);
NODE_SET_METHOD(exports, "restoreAccountAndLogin", _RestoreAccountAndLogin); NODE_SET_METHOD(exports, "restoreAccountAndLogin", _RestoreAccountAndLogin);
} }

View File

@ -535,10 +535,6 @@
[] []
(.logFileDirectory ^js (log-manager))) (.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 (defn get-random-mnemonic
[callback] [callback]
(.getRandomMnemonic ^js (account-manager) #(callback (types/json->clj %)))) (.getRandomMnemonic ^js (account-manager) #(callback (types/json->clj %))))

View File

@ -2,11 +2,8 @@
(:require (:require
[clojure.pprint :as pprint] [clojure.pprint :as pprint]
[clojure.string :as string] [clojure.string :as string]
[native-module.core :as native-module]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.config :as config] [taoensso.timbre :as log]))
[taoensso.timbre :as log]
[utils.transforms :as transforms]))
(def logs-queue (atom #queue [])) (def logs-queue (atom #queue []))
(def max-log-entries 1000) (def max-log-entries 1000)
@ -21,19 +18,8 @@
(defn setup (defn setup
[level] [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"}}}) (log/merge-config! {:ns-filter {:allow #{"*"} :deny #{"taoensso.sente"}}})
(if (string/blank? level) (when-not (string/blank? level)
(native-module/init-status-go-logging (merge logging-params {:log-level "WARN"}))
(do
(log/set-min-level! (-> level (log/set-min-level! (-> level
string/lower-case string/lower-case
keyword)) keyword))
@ -46,8 +32,7 @@
(update data (update data
:vargs :vargs
(partial mapv (partial mapv
#(if (string? %) % (with-out-str (pprint/pprint %))))))]}) #(if (string? %) % (with-out-str (pprint/pprint %))))))]})))
(native-module/init-status-go-logging logging-params)))))
(re-frame/reg-fx (re-frame/reg-fx
:logs/set-level :logs/set-level

View File

@ -71,7 +71,7 @@
;; CONFIG VALUES ;; CONFIG VALUES
(def log-level (string/upper-case (get-config :LOG_LEVEL ""))) (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 fleet (get-config :FLEET ""))
(def apn-topic (get-config :APN_TOPIC "im.status.ethereum")) (def apn-topic (get-config :APN_TOPIC "im.status.ethereum"))
(def max-installations 2) (def max-installations 2)

View File

@ -1,5 +1,6 @@
(ns status-im.contexts.profile.events (ns status-im.contexts.profile.events
(:require (:require
[clojure.string :as string]
[legacy.status-im.data-store.settings :as data-store.settings] [legacy.status-im.data-store.settings :as data-store.settings]
[legacy.status-im.multiaccounts.update.core :as multiaccounts.update] [legacy.status-im.multiaccounts.update.core :as multiaccounts.update]
[native-module.core :as native-module] [native-module.core :as native-module]
@ -36,7 +37,10 @@
{:dataDir (native-module/backup-disabled-data-dir) {:dataDir (native-module/backup-disabled-data-dir)
:mixpanelAppId config/mixpanel-app-id :mixpanelAppId config/mixpanel-app-id
:mixpanelToken config/mixpanel-token :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))) callback)))
(rf/reg-event-fx (rf/reg-event-fx

View File

@ -116,15 +116,7 @@
(def log-manager (def log-manager
(clj->js (clj->js
{:logFileDirectory {:logFileDirectory
(fn [] (str test-dir "/log")) (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")}))))}))
(def network (def network
(clj->js (clj->js

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v6.0.0", "version": "v6.1.0",
"commit-sha1": "83ea49fc04cd521864a64fd2d94d4e5309a81645", "commit-sha1": "c014fbfc1ec739aad2db951fdcff6182d4dbd919",
"src-sha256": "0f93s1yr8p24aw9ji5wsmq07vf4599nk4bhr55q0ifx0szhabilx" "src-sha256": "16im0nc8zri5z1wvzbh83331g02iy305m2lca4ljjgdmlaq6l2zx"
} }

View File

@ -117,7 +117,7 @@ def pull_geth(driver):
def pull_requests_log(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) return base64.b64decode(result)