From ce08265e0df4d69e7b26e0ca37ba93893f74695c Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Tue, 3 Jan 2023 21:17:13 +0100 Subject: [PATCH] chore: re-enable logging in prod version closes: #8932 --- Makefile | 2 +- src/app/boot/app_controller.nim | 16 +++++++++++++++- .../profile_section/advanced/controller.nim | 6 +++--- .../service/node_configuration/service.nim | 19 ++++++++++++++++--- src/nim_status_client.nim | 17 ++++++++--------- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index ddef04ab49..b60b073dfd 100644 --- a/Makefile +++ b/Makefile @@ -409,7 +409,7 @@ $(FCITX5_QT): | check-qt-dir deps .. $(HANDLE_OUTPUT) && \ $(FCITX5_QT_BUILD_CMD) -PRODUCTION_PARAMETERS := -d:production -d:chronicles_sinks=textlines[stdout],textlines[nocolors,dynamic] +PRODUCTION_PARAMETERS := -d:production $(STATUS_CLIENT_APPIMAGE): override RESOURCES_LAYOUT := $(PRODUCTION_PARAMETERS) $(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop $(FCITX5_QT) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index b20cfe7991..ce1eb34768 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -1,4 +1,4 @@ -import NimQml, sequtils, sugar, chronicles +import NimQml, sequtils, sugar, chronicles, os import ../../app_service/service/general/service as general_service import ../../app_service/service/keychain/service as keychain_service @@ -116,6 +116,15 @@ proc connect(self: AppController) = # not sure, but maybe we should take some actions when node stops discard + # Handle runtime log level settings changes + if not existsEnv("LOG_LEVEL"): + self.statusFoundation.events.on(node_configuration_service.SIGNAL_NODE_LOG_LEVEL_UPDATE) do(a: Args): + let args = NodeLogLevelUpdatedArgs(a) + if args.logLevel == LogLevel.DEBUG: + setLogLevel(LogLevel.DEBUG) + elif defined(production): + setLogLevel(LogLevel.INFO) + proc newAppController*(statusFoundation: StatusFoundation): AppController = result = AppController() result.storeKeyPair = false @@ -345,6 +354,11 @@ proc load(self: AppController) = self.tokenService.init() self.walletAccountService.init() + # Apply runtime log level settings + if not existsEnv("LOG_LEVEL"): + if self.nodeConfigurationService.isDebugEnabled(): + setLogLevel(LogLevel.DEBUG) + # load main module self.mainModule.load( self.statusFoundation.events, diff --git a/src/app/modules/main/profile_section/advanced/controller.nim b/src/app/modules/main/profile_section/advanced/controller.nim index 7045aca47d..4004a0afcc 100644 --- a/src/app/modules/main/profile_section/advanced/controller.nim +++ b/src/app/modules/main/profile_section/advanced/controller.nim @@ -72,7 +72,7 @@ proc setWakuV2LightClientEnabled*(self: Controller, enabled: bool) = proc enableDeveloperFeatures*(self: Controller) = discard self.settingsService.saveTelemetryServerUrl(DEFAULT_TELEMETRY_SERVER_URL) discard self.settingsService.saveAutoMessageEnabled(true) - discard self.nodeConfigurationService.setDebugLevel(LogLevel.DEBUG) + discard self.nodeConfigurationService.setLogLevel(LogLevel.DEBUG) quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported @@ -104,14 +104,14 @@ proc isAutoMessageEnabled*(self: Controller): bool = return self.settingsService.autoMessageEnabled() proc isDebugEnabled*(self: Controller): bool = - return self.nodeConfigurationService.getDebugLevel() == $LogLevel.DEBUG + return self.nodeConfigurationService.isDebugEnabled() proc toggleDebug*(self: Controller) = var logLevel = LogLevel.DEBUG if(self.isDebugEnabled()): logLevel = LogLevel.INFO - if(not self.nodeConfigurationService.setDebugLevel(logLevel)): + if(not self.nodeConfigurationService.setLogLevel(logLevel)): # in the future we may do a call from here to show a popup about this error error "an error occurred, we couldn't toggle debug level" return diff --git a/src/app_service/service/node_configuration/service.nim b/src/app_service/service/node_configuration/service.nim index f4a10d705a..ba1c059328 100644 --- a/src/app_service/service/node_configuration/service.nim +++ b/src/app_service/service/node_configuration/service.nim @@ -18,6 +18,12 @@ const BLOOM_LEVEL_NORMAL* = "normal" const BLOOM_LEVEL_FULL* = "full" const BLOOM_LEVEL_LIGHT* = "light" +const SIGNAL_NODE_LOG_LEVEL_UPDATE* = "nodeLogLevelUpdated" + +type + NodeLogLevelUpdatedArgs* = ref object of Args + logLevel*: LogLevel + type ErrorArgs* = ref object of Args msg*: string @@ -244,13 +250,20 @@ proc setV2LightMode*(self: Service, enabled: bool): bool = newConfiguration.WakuV2Config.LightClient = enabled return self.saveConfiguration(newConfiguration) -proc getDebugLevel*(self: Service): string = +proc getLogLevel(self: Service): string = return self.configuration.LogLevel -proc setDebugLevel*(self: Service, logLevel: LogLevel): bool = +proc isDebugEnabled*(self: Service): bool = + return self.getLogLevel() == $LogLevel.DEBUG + +proc setLogLevel*(self: Service, logLevel: LogLevel): bool = var newConfiguration = self.configuration newConfiguration.LogLevel = $logLevel - return self.saveConfiguration(newConfiguration) + if self.saveConfiguration(newConfiguration): + self.events.emit(SIGNAL_NODE_LOG_LEVEL_UPDATE, NodeLogLevelUpdatedArgs(logLevel: logLevel)) + return true + else: + return false proc isV2LightMode*(self: Service): bool = return self.configuration.WakuV2Config.LightClient diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 023e63dee9..8549f763b6 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -52,17 +52,16 @@ proc prepareLogging() = except: logLoggingFailure(cstring(msg), getCurrentException()) - # do not create log file - when not defined(production): - # log level can be overriden by LOG_LEVEL env parameter - let logLvl = try: parseEnum[LogLevel](getEnv("LOG_LEVEL")) - except: NONE + let defaultLogLvl = if defined(production): LogLevel.INFO else: LogLevel.DEBUG + # default log level can be overriden by LOG_LEVEL env parameter + let logLvl = try: parseEnum[LogLevel](getEnv("LOG_LEVEL")) + except: defaultLogLvl - setLogLevel(logLvl) + setLogLevel(logLvl) - let formattedDate = now().format("yyyyMMdd'_'HHmmss") - let logFile = fmt"app_{formattedDate}.log" - discard defaultChroniclesStream.outputs[1].open(LOGDIR & logFile, fmAppend) + let formattedDate = now().format("yyyyMMdd'_'HHmmss") + let logFile = fmt"app_{formattedDate}.log" + discard defaultChroniclesStream.outputs[1].open(LOGDIR & logFile, fmAppend) proc setupRemoteSignalsHandling() = # Please note that this must use the `cdecl` calling convention because