From 0fc01cd530ca4443b30ef13ce3fec52e08a68fd1 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Fri, 29 Nov 2024 15:44:26 +0000 Subject: [PATCH] feat: status-go API logging option (#16808) * chore_: move toStatusGoSupportedLogLevel * feat_: initialize status-go log * fix_: proper read of error in InitializeAPplication * chore_: bump status-go --- src/app_service/service/accounts/service.nim | 9 ++------- src/backend/accounts.nim | 10 +++++++++- src/constants.nim | 6 ++++++ src/env_cli_vars.nim | 6 ++++++ vendor/status-go | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/app_service/service/accounts/service.nim b/src/app_service/service/accounts/service.nim index 76d14aa45c..01630516b3 100644 --- a/src/app_service/service/accounts/service.nim +++ b/src/app_service/service/accounts/service.nim @@ -135,11 +135,6 @@ QtObject: proc openedAccountsContainsKeyUid*(self: Service, keyUid: string): bool = return (keyUID in self.openedAccounts().mapIt(it.keyUid)) - proc toStatusGoSupportedLogLevel*(logLevel: string): string = - if logLevel == "TRACE": - return "DEBUG" - return logLevel - # FIXME: remove this method, settings should be processed in status-go # https://github.com/status-im/status-go/issues/5359 proc addKeycardDetails(self: Service, kcInstance: string, settingsJson: var JsonNode, accountData: var JsonNode) = @@ -182,7 +177,7 @@ QtObject: rootDataDir: main_constants.STATUSGODIR, kdfIterations: KDF_ITERATIONS, customizationColor: DEFAULT_CUSTOMIZATION_COLOR, - logLevel: some(toStatusGoSupportedLogLevel(main_constants.LOG_LEVEL)), + logLevel: some(main_constants.getStatusGoLogLevel()), wakuV2LightClient: false, wakuV2EnableMissingMessageVerification: true, wakuV2EnableStoreConfirmationForMessagesSent: true, @@ -389,7 +384,7 @@ QtObject: ) if main_constants.runtimeLogLevelSet(): - request.runtimeLogLevel = toStatusGoSupportedLogLevel(main_constants.LOG_LEVEL) + request.runtimeLogLevel = main_constants.getStatusGoLogLevel() let response = status_account.loginAccount(request) diff --git a/src/backend/accounts.nim b/src/backend/accounts.nim index a2b61e470d..923ead6b08 100644 --- a/src/backend/accounts.nim +++ b/src/backend/accounts.nim @@ -264,6 +264,10 @@ proc openedAccounts*(path: string): RpcResponse[JsonNode] = "mixpanelAppId": MIXPANEL_APP_ID, "mixpanelToken": MIXPANEL_TOKEN, "sentryDSN": SENTRY_DSN_STATUS_GO, + "logEnabled": true, + "logDir": "", # Empty value defaults to `dataDir` + "logLevel": status_const.getStatusGoLogLevel(), + "apiLoggingEnabled": status_const.API_LOGGING, } # Do not remove the sleep 700 # This sleep prevents a crash on intel MacOS @@ -271,7 +275,11 @@ proc openedAccounts*(path: string): RpcResponse[JsonNode] = if status_const.IS_MACOS and status_const.IS_INTEL: sleep 700 let response = status_go.initializeApplication($payload) - result.result = Json.decode(response, JsonNode) + let jsonResponse = parseJson(response) + let error = jsonResponse{"error"}.getStr() + if error.len > 0: + raise newException(RpcException, error) + result.result = jsonResponse except RpcException as e: error "error doing rpc request", methodName = "openedAccounts", exception=e.msg raise newException(RpcException, e.msg) diff --git a/src/constants.nim b/src/constants.nim index 8d9f57ac49..d4822fcc7e 100644 --- a/src/constants.nim +++ b/src/constants.nim @@ -66,6 +66,7 @@ let WS_API_ENABLED* = desktopConfig.wsApiEnabled SENTRY_DSN_STATUS_GO* = BUILD_SENTRY_DSN_STATUS_GO SENTRY_DSN_STATUS_GO_DESKTOP* = BUILD_SENTRY_DSN_STATUS_DESKTOP + API_LOGGING* = desktopConfig.apiLogging proc hasLogLevelOption*(): bool = for p in cliParams: @@ -76,4 +77,9 @@ proc hasLogLevelOption*(): bool = proc runtimeLogLevelSet*(): bool = return existsEnv(RUN_TIME_PREFIX & "_LOG_LEVEL") or hasLogLevelOption() +proc getStatusGoLogLevel*(): string = + if LOG_LEVEL == "TRACE": + return "DEBUG" + return LOG_LEVEL + const MAIN_STATUS_SHARD_CLUSTER_ID* = 16 diff --git a/src/env_cli_vars.nim b/src/env_cli_vars.nim index 0cca223d97..627b3244bd 100644 --- a/src/env_cli_vars.nim +++ b/src/env_cli_vars.nim @@ -33,6 +33,7 @@ const BASE_NAME_MIXPANEL_APP_ID = "MIXPANEL_APP_ID" const BASE_NAME_MIXPANEL_TOKEN = "MIXPANEL_TOKEN" const BASE_NAME_SENTRY_DSN_STATUS_GO = "SENTRY_DSN_STATUS_GO" const BASE_NAME_SENTRY_DSN_STATUS_DESKTOP = "SENTRY_DSN_STATUS_DESKTOP" +const BASE_NAME_API_LOGGING = "API_LOGGING" ################################################################################ @@ -249,6 +250,11 @@ type StatusDesktopConfig = object desc: "Enable WebSocket RPC API" name: "WS_API" abbr: "ws-api" .}: bool + apiLogging* {. + defaultValue: false + desc: "Enables status-go API logging" + name: $BASE_NAME_API_LOGGING + abbr: "api-logging" .}: bool # On macOS the first time when a user gets the "App downloaded from the # internet" warning, and clicks the Open button, the OS passes a unique process diff --git a/vendor/status-go b/vendor/status-go index 5a69c686cf..cdc41c3b64 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 5a69c686cfed4b4d9436be7f4e946d824a2e20ca +Subproject commit cdc41c3b6459924b9ac30e1b60b34669e48984bd