chore: re-enable logging in prod version

closes: #8932
This commit is contained in:
Patryk Osmaczko 2023-01-03 21:17:13 +01:00 committed by osmaczko
parent b8a1c70d62
commit ce08265e0d
5 changed files with 43 additions and 17 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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